archesproject / arches

Arches is a web platform for creating, managing, & visualizing geospatial data. Arches was inspired by the needs of the Cultural Heritage community, particularly the widespread need of organizations to build & manage cultural heritage inventories
GNU Affero General Public License v3.0
216 stars 144 forks source link

`get_resource_types_by_perm` should fully leverage caching #11217

Open whatisgalen opened 3 months ago

whatisgalen commented 3 months ago

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)
whatisgalen commented 3 months ago

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