Jump to content

A question of performance


rajo
 Share

Recommended Posts

Hi all,

I'm wondering what the faster, most scalable, way to populate a search criterion <select> control would be, in a case as follows:

Let's say there's a list of colour pages:   red, blue, etc...

They are referenced as thing->colours in the thing template, in a multi-value Page field.  It's possible not all colours are actually assigned to things (e.g. maybe no thing has green in its colours field).

Now, in the search form, if I build a <select> as follows, I'll end up w/ "green", which invites empty search results -- teasing the user...

        foreach($pages->find("template=colour,sort=sort") as $item) { ... }

Here's my current solution. I'm wondering whether it'll scale and perform.  In the following code, I exclude MarkupCache to keep the logic clearer:

$things = $pages->find('template=thing');

$ids = implode( '|', array_unique( explode( '|', $things->implode('|', 'colours')), SORT_NUMERIC));

foreach($pages->find("id={$ids},sort=sort") as $item) { ... }

$things could be a rather large PageArray.  Is PageArray->implode() efficient?  Is array_unique efficient?

Yes, I could do measurements, but I was wondering whether this common problem already had been given some thought?

Bueller?  

Many thanks.

Jean

Link to comment
Share on other sites

foreach($pages->find("template=colour,sort=sort") as $item) {
  if($pages->get("template=thing, colour=$item")->id){
    //There are actually pages with this colour
  }
}

Regarding your performance question: Loading one page per color should be nicer than loading all $thing pages. Even without all your sorting stuff.

  • Like 1
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...