pimcore / data-hub

Data delivery & consumption platform for Pimcore.
Other
128 stars 110 forks source link

[Improvement][Perf]: WorkspaceHelper::isAllowed creating hundreds of database queries for listings #886

Closed dkarlovi closed 2 weeks ago

dkarlovi commented 2 months ago

Improvement description

WorkspaceHelper::isAllowed will run a DB query for each item in the listing, including relations: https://github.com/pimcore/data-hub/blob/f78112706afa25a590f3519d9ee9364df742ea2f/src/WorkspaceHelper.php#L280-L282

In my test, fetching 50 products and related images will run the query 426 times, accounting for about 30% of the total runtime.

Untitled-profile-Blackfire (1)

Looking at the code, it seems it should be possible to avoid these queries completely by creating a special in-memory (in cache) data structure optimized for this check and running the check as fast as possible on that specific structure.

Edit: when the listing is fully cached (all elements fully resolved from cache), the listing will still run 546 queries, but 426 of them are still this permission check, that's 80% of all the work done, accounting for 40% of total runtime.

fashxp commented 1 month ago

related to https://github.com/pimcore/data-hub/issues/300?

dkarlovi commented 1 month ago

@fashxp not sure what you're asking or if you're even asking me.

fashxp commented 1 month ago

@dkarlovi just linking potentially related issues - not sure though if this is the same topic.