#2296 closed enhancement (fixed)

Improve performance when loading many any-to-any links

Reported by: Nicklas Nordborg Owned by: everyone
Priority: major Milestone: BASE 3.19.8
Component: core Version:
Keywords: Cc:

Description

The use case is that we have long list of items (of the same known item type) and want to load the same named any-to-any link for all of them. This is typically done with:

AnyToAny link = AnyToAny.getByName(...);
XxxxItem linkedItem = link.getTo();

This typically require two extra database calls. One call to load the link and one to load the linked item. Performance for this is bad when we have to repeat this many times.

To increase the performance the idea is to implement a helper object that can load all links with a single query and all target items with a single query.

See also https://baseplugins.thep.lu.se/ticket/1470

Change History (3)

comment:1 by Nicklas Nordborg, 14 months ago

In 8130:

References #2296: Improve performance when loading many any-to-any links

Added AnyToAny.getFastLoader() which returns a FastLinkLoader instance for loading any-to-any links with fixed link name between source and target item types.

The fast loaded need to be pre-loaded with items before it can be used. The simplest way is to use FastLinkLoader.preloadAll() but there is also an alternative that allows a subset of the links to be pre-loaded.

comment:2 by Nicklas Nordborg, 14 months ago

In 8131:

References #2296: Improve performance when loading many any-to-any links

The DataQuery class uses the stateless Hibernate session which is causing a lot of extra queries while iterating (since the statless session doesn't support lazy proxies). Switched to AbstractEntityQuery instead which allows us to use the stateful session.

comment:3 by Nicklas Nordborg, 13 months ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.