Skip to content

Commit

Permalink
Merge pull request #11458 from archesproject/11457_report_slowdown
Browse files Browse the repository at this point in the history
lookup readable_graphids 1 time instead of N times in get_related_res…
  • Loading branch information
apeters authored Sep 18, 2024
2 parents a8f090d + 4a18954 commit 8aeecef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions arches/app/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,11 @@ def get_relations(
restricted_instances = (
get_restricted_instances(user, se) if user is not None else []
)
readable_graphids = set(
permission_backend.get_resource_types_by_perm(
user, ["models.read_nodegroup"]
)
)
for relation in resource_relations["relations"]:
relation = model_to_dict(relation)
resourceid_to = relation["resourceinstanceidto"]
Expand All @@ -872,8 +877,8 @@ def get_relations(
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)
and str(resourceinstanceto_graphid) in readable_graphids
and str(resourceinstancefrom_graphid) in readable_graphids
):
try:
preflabel = get_preflabel_from_valueid(
Expand Down
10 changes: 10 additions & 0 deletions tests/views/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,16 @@ def test_get_resource_jsonld_invalid_no_ontology(self):

self.assertEqual(response.status_code, 400)

def test_resource_report_api(self):
self.client.login(username="admin", password="admin")
response = self.client.get(
reverse(
"api_resource_report",
args=(str(self.test_prj_user.pk),),
),
)
self.assertEqual(response.status_code, 200)

def test_related_resources_in_resource_report_api(self):
self.client.login(username="admin", password="admin")
response = self.client.get(
Expand Down

0 comments on commit 8aeecef

Please sign in to comment.