eZ Community » Forums » eZ Publish 5 Platform » Avoiding N+1 queries and dealing with...
expandshrink

Avoiding N+1 queries and dealing with multiple locations

Avoiding N+1 queries and dealing with multiple locations

Thursday 21 November 2013 8:57:11 am - 2 replies

Hi all,

I have two questions about fetching Content/Location and the SearchService::findContent() API that I hope someone can help answer:

Q1: When using the SearchService::findContent() API, is there any way to avoid having to do N+1 queries to get the Location as well?

E.g if you want to fetch a list of 50 Content objects and their locations you'll end up with 51 queries! The current approach seems to be to use findContent() and the loop over the result and fetch each location: https://github.com/ezsystems/Demo...er/Controller/DemoController.php#L54

Is there was a way to tell the API to join in the Location data as well?

Q2: Say I have the following structure:

- Sports [Folder]
    - Arsenal wins the Premier League [Article, main location]
- Domestic News [Folder]
    - Arsenal wins the Premier League [Article] 

and I do a query with a Criterion\ParentLocationId of Domestic News, how do I then grab and link to the Location of the article under Domestic new? As far as I can see the Content valueObject that is returned only has a mainLocationId attribute which would point to the location under Sports... The only way I could think of accomplish this (which is very tedious) is to fetch all the locations of the Article, loop through and compare the parent id with the id of Domestic News. Is there a better way?

 

Cheers,

Ole

Modified on Thursday 21 November 2013 9:51:52 am by Ole Morten Halvorsen

Thursday 21 November 2013 12:11:54 pm

Hi, currently there is no way to tell it to add locations in there on its own.
So at the moment only comfort I can give is that the locations fetches should be cached by persistence cache.

We will consider doing this though, but maybe not before we have the Solr search up and running, maybe able to build up the objects purely based on the search results even.

Modified on Thursday 21 November 2013 12:13:45 pm by André R

Friday 22 November 2013 1:03:37 am

Thanks for the answer André!

Cheers,

Ole

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from