On 22 Aug 2018, at 19:50, Thomas Klausner <[email protected]> wrote:
>
> Hi!
>
> On Wed, Aug 22, 2018 at 07:14:39PM +0100, Andy Armstrong wrote:
>
>> With DBIC every call to $prog->service->name results in a query
>> against services - so for a page of 20 search results that's 20
>> additional queries. Even on a single page it's often the case that
>> many of those queries are searching for the same service.
>
> Take a look at 'prefetch', which will fetch all of the data from the
> related table, so your search will be again one query only.
Thanks Thomas - that just about does it.
I should perhaps have mentioned that services may also do a self join to find a
parent service - services are either one or two levels deep. I can make
prefetch work for a single level service and I can make it work for two level
services but not, as far as I can see, for both.
If I do prefetch => ['service', { service => 'parent' }] I only get results for
the cases where the service hierarchy is two levels deep.
Having said that I inherited the self-join hierarchical service table - that
could probably be refactored so that all services are a super-service -
sub-service hierarchy which would, I think, solve the problem.
Thanks :)
--
Andy Armstrong, Hexten
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]