On Jan 18, 3:52 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> cake 1.2.0.6311-beta, PHP 5.2.4
>
> I'm trying to use afterFind() in order to massage some data for a
> model and am seeing PHP max out the memory limit (32MB). I'm only
> using a subset of just 1000 records (about 5%) from the prod. DB
> membership table. I'm using a technique that I saw given to create a
> "full_name" field in the returned array by concating the first & last
> names. In my case, I'm running urlencode()  on the members' names to
> create a new field, among other things.
>
> Part of the problem is that the fields i'm looking for might lie at
> any of a number of levels, depending on whether i'm viewing a single
> record or selecting many. So I have to do stuff lik this:
>
> function afterFind($results)
> {
>         if (isset($results['id']))
>         {
>                 ...
>                 return $results;
>         }
>
>         foreach ($results as $key => $val)
>         {
>                 if(array_key_exists($this->name, $val) && 
> isset($results[$key][$this->name]['id']))
>
>                 {
>                         ...
>                 }
>                 else if (isset($results[$key]['id']))
>                 {
>                         ...
>                 }
>         }
>         return $results;
>
> }
>
> Selecting 1000 records ate through memory pretty quick, so I limited
> the fields to just id, first_name, last_name, organisation, and email
> to start  with.
>
> However, even with just those fields selected, I was still running out
> of memory. It turned out that it was the methods I was passing my
> array values to in order to create new fields. eg:
>
> $results['link_name'] = $this->linkName($result['first_name'],
> $results['last_name']);
>
> where linkName() is just:
>
> return urlencode("${first_name}_${last_name}");
>
> By taking out the method calls and repeating the same logic at each
> level I was finally able to run this. However, now I'm finding that
> afterFind() is called for every little query, including just looking
> up an ID. So now I'm faced with placing even more logic in afterFind()
> -- not a great prospect.
>
> So, as the subject suggests, I was poking around the Set class trying
> to figure out if there was some way to use that for this problem. But
> I can't think of anything that wouldn't likely cause even more memory
> issues.
>
> Basically, I'm not even sure if I'm going about this the right way. Is
> this an appropriate way to use afterind()? Is there a simpler way to
> get at my Member data, no matter if it's just a single record or many?

32MB of memory is a bit stingy.

How about
1) delete your afterFind method
2) include "CONCAT(". $model->escapeField('first_name').','.$model-
>escapeField('last_name').') AS full_name'"
3) look for $result[0]['full_name'] instead of $result['User']
['first_name'] etc.
4) url_encode where you need it (in the view)

Alternatively, to use the set class to do it would be something like:
$keyPath = '{n}.User.id';
$valuePath = array('{0} {1}', '{n}.User.first_name',
'{n}.User.last_name');
$results = Set::combine($results, $keyPath, $valuePath);

hth,

AD

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to