php - One query per each entity -
imagine have arraycollection, containing several doctrine entities instance of country. imagine method 'getname()' is, in fact, 1 many relation several languages ( a2lixtranslation support )...
the point arraycollection built elasticsearch service, when retrieve these entities, iterate them , print name, query every category.
i don't know how manage situation, 150 queries not mainainable...
example implementation
$countries = // arraycollection of countries, returned mapping system. foreach ($countries $country) { /** * name entity, uses lazy loading in every iteration * because collection comes, retrieve * names in 1 query. thought perform dql join * of countries , names, doctrine catch'em * catch query , results, , not identify retrieved * results collection, not working... */ $name = $country->getname(); echo $name; } // nice this... $countries = // arraycollection of countries, returned mapping system. $querybuilder = $this ->getdoctrine() ->getrepository('projectcorebundle:country') ->createquerybuilder('c'); /** * query result should add cache results */ $querybuilder ->select('c','t') ->innerjoin('c.countryname','cn','with','c.id = cn.country') ->getquery() ->getresult(); foreach ($countries $country) { /** * @ poing, name relation entity loaded , cached * lazy load return object ( query performed ) */ $name = $country->getname(); echo $name; }
i recommend taking @ multi search api endpoint in elasticsearch: http://www.elasticsearch.org/guide/reference/api/multi-search/. allow prepare single web request multiple queries; es return same number of responses number of queries in requests. shaves down network communication time.
i think alternative restructure code/data/thinking allow perform single query information looking for, don't think there's enough information dig deeper here.
Comments
Post a Comment