Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dkarlovi opened this issue Sep 19, 2024 · 3 comments · May be fixed by #889
Open
Milestone

Comments

@dkarlovi
Copy link

dkarlovi commented Sep 19, 2024

Improvement description

WorkspaceHelper::isAllowed will run a DB query for each item in the listing, including relations:

$db = Db::get();
$sql = 'SELECT `' . $type . '` FROM plugin_datahub_workspaces_' . $elementType . ' WHERE cid IN (' . implode(',', $parentIds) . ') AND configuration = ' . $db->quote($configuration->getName()) . ' AND `' . $type . '`=1 ORDER BY LENGTH(cpath) DESC LIMIT 1';
$permissionsParent = $db->fetchOne($sql);

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
Copy link
Member

fashxp commented Oct 1, 2024

related to #300?

@dkarlovi
Copy link
Author

dkarlovi commented Oct 2, 2024

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

@fashxp
Copy link
Member

fashxp commented Oct 2, 2024

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

@fashxp fashxp added this to the 1.9.0 milestone Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants