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

get_related_resources() calls user_can_read_graph() multiple times for same graphs, huge slowdown #11457

Closed
whatisgalen opened this issue Sep 16, 2024 · 1 comment

Comments

@whatisgalen
Copy link
Member

whatisgalen commented Sep 16, 2024

At this section of get_related_resources method (used by the resource_report API endpoint):

for relation in resource_relations["relations"]:
            relation = model_to_dict(relation)
            resourceid_to = relation["resourceinstanceidto"]
            resourceid_from = relation["resourceinstanceidfrom"]
            resourceinstanceto_graphid = relation["resourceinstanceto_graphid"]
            resourceinstancefrom_graphid = relation["resourceinstancefrom_graphid"]

            if (
                resourceid_to not in restricted_instances
                and resourceid_from not in restricted_instances
                and user_can_read_graph(user, resourceinstanceto_graphid)
                and user_can_read_graph(user, resourceinstancefrom_graphid)
            ):
            ...

the user_can_read_graph permissions method makes an ORM query every time it's called, even on relations shows graph we've already check. This can slow things down significantly, to the point where a single report takes up to 2 minutes to load. The slowdown is especially noticeable for resources with 50+ relations

@whatisgalen whatisgalen changed the title get_related_resources() calls user_can_read_graph() multiple times for same graphs get_related_resources() calls user_can_read_graph() multiple times for same graphs, huge slowdown Sep 16, 2024
@chiatt chiatt added this to pipeline Sep 16, 2024
@whatisgalen
Copy link
Member Author

completed in #11458

@github-project-automation github-project-automation bot moved this to ✅ Done in pipeline Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

1 participant