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_resource_types_by_perm should fully leverage caching #11217

Open
whatisgalen opened this issue Jul 20, 2024 · 1 comment
Open

get_resource_types_by_perm should fully leverage caching #11217

whatisgalen opened this issue Jul 20, 2024 · 1 comment

Comments

@whatisgalen
Copy link
Member

whatisgalen commented Jul 20, 2024

get_resource_types_by_perm can get called many times when assigning permissions to search results. It calls get_nodegroups_by_perm which does leverage caching, but then proceeds to do an ORM query every single time it's called.

def get_resource_types_by_perm(
        self, user: User, perms: str | Iterable[str]
    ) -> list[str]:
        nodegroups = self.get_nodegroups_by_perm(user, perms)
        graphs = (
            Node.objects.values("graph_id")
            .filter(
                Q(nodegroup__in=nodegroups)
                & ~Q(graph_id=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID)
                & Q(graph__isresource=True)
            )
            .values_list("graph_id", flat=True)
        )

        return list(str(graph) for graph in graphs)
@chiatt chiatt added this to pipeline Jul 20, 2024
@whatisgalen whatisgalen changed the title get_resource_types_by_perm should leverage CachedObjectPermissionChecker get_resource_types_by_perm should fully leverage caching Jul 20, 2024
@whatisgalen
Copy link
Member Author

@philtweir interested if F&T had a different approach when it came to this ORM query in get_resource_types_by_perm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

1 participant