Jump to content

How to get array of page ids by selector if there are 10000+ pages?


valan
 Share

Recommended Posts

Is it possible to search pages by selector and get array (or separated string) of page ids instead of populated Pages in PageArray?

I have several thousands of pages in return and want to avoid memory limit/performance issues. All I need are page ids.

Link to comment
Share on other sites

Not knowing exactly what you want to do it's difficult to help, but it seems to me that it would be better to use "limit" on the selector and do whatever you have to do in chunks. Honestly I don't see how an array of 10000 IDs could be useful.

Link to comment
Share on other sites

A "getIds" option might be nice. 

$pages->find($selector, array('getIds' => true));

It would be in a similar vane to:

$pages->getByPath('/path/to/page', array('getID' => true));

but would obviously return an array of IDs, rather than a single one like with getByPath.

Or maybe:

$pages->getIds($selector);

which has the same feel as:

$pages->count($selector);
  • Like 2
Link to comment
Share on other sites

PageFinder has a findIDs() method that sets the returnVerbose attribute. It doesn't set loadPages attribute, but I presume when returnVerbose is off it automatically does not return pages.

Untested, but this should work: (Oops. Doesn't work. See below.)

$pages->findIDs($selector);
  • Like 1
Link to comment
Share on other sites

PageFinder has a findIDs() method that sets the returnVerbose attribute. It doesn't set loadPages attribute, but I presume when returnVerbose is off it automatically does not return pages.

Untested, but this should work:

$pages->findIDs($selector);

I thought I remembered there being something like that, but couldn't find it. Thanks for the reminder!

PS And of course findIDs makes much more sense than my suggest getIds :)

Link to comment
Share on other sites

That's not going to work like that. First of all $pages is not pageFinder, $pages->pageFinder() is. Also the first argument is typehinted to Selectors, so putting a string won't work as well. That's why I've not mentioned it as I find it more confusing to use instead of the simple "add those options". If there would be a companion function in the Pages class it would be nice.

$pages->pageFinder()->findIDs(new Selectors($selector));
  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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