diff --git a/arches/app/models/resource.py b/arches/app/models/resource.py index 9cafd8f7b8e..54ceb3b5445 100644 --- a/arches/app/models/resource.py +++ b/arches/app/models/resource.py @@ -859,6 +859,7 @@ def get_relations( ret["total"] = {"value": resource_relations["total"]} instanceids = set() + preflabel_lookup = dict() readable_graphids = set( permission_backend.get_resource_types_by_perm( @@ -895,9 +896,18 @@ def get_relations( and str(resourceinstancefrom_graphid) in readable_graphids ): try: - preflabel = get_preflabel_from_valueid( - relation["relationshiptype"], lang - ) + if f'{relation["relationshiptype"]}{lang}' in preflabel_lookup: + preflabel = preflabel_lookup[ + f'{relation["relationshiptype"]}{lang}' + ] + else: + preflabel = get_preflabel_from_valueid( + relation["relationshiptype"], lang + ) + preflabel_lookup[f'{relation["relationshiptype"]}{lang}'] = ( + preflabel + ) + relation["relationshiptype_label"] = preflabel["value"] or "" except: relation["relationshiptype_label"] = ( diff --git a/releases/7.6.4.md b/releases/7.6.4.md index 80df85c3c6f..c321eda81bf 100644 --- a/releases/7.6.4.md +++ b/releases/7.6.4.md @@ -5,6 +5,7 @@ - Remove unnecessary creation of guardian permissions for principal user #[11564](https://github.com/archesproject/arches/issues/11564) - Fix Graph Designer failure when editing large graphs #[11615](https://github.com/archesproject/arches/issues/11615) - Fix failure to download exported search results when using non file-system based storages #[11620](https://github.com/archesproject/arches/issues/11620) +- Cache resource relationship preflabels to improve report load time #[11583](https://github.com/archesproject/arches/issues/11583) ### Dependency changes: diff --git a/tests/test_settings.py b/tests/test_settings.py index 78982437c8b..da9d69a4a83 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -44,6 +44,7 @@ "graphs", "resource_models", ), + os.path.join(TEST_ROOT, "fixtures", "jsonld_base", "models"), ] REFERENCE_DATA_FIXTURE_LOCATION = os.path.join( TEST_ROOT, "fixtures", "testing_prj", "testing_prj", "pkg", "reference_data" diff --git a/tests/views/resource_tests.py b/tests/views/resource_tests.py index d250d1ec7ec..68507887da2 100644 --- a/tests/views/resource_tests.py +++ b/tests/views/resource_tests.py @@ -21,6 +21,10 @@ from tests.base_test import ArchesTestCase from django.urls import reverse from arches.app.models.models import EditLog, ResourceInstance +from arches.app.models.resource import Resource +from arches.app.models.tile import Tile +from tests.utils.search_test_utils import sync_es +from arches.app.search.search_engine_factory import SearchEngineFactory from arches.app.utils.betterJSONSerializer import JSONSerializer from django.contrib.auth.models import User from django.contrib.auth.models import Group @@ -36,9 +40,12 @@ class CommandLineTests(ArchesTestCase): - graph_fixtures = ["Data_Type_Model"] + graph_fixtures = ["Data_Type_Model", "4564-referenced", "4564-person"] data_type_graphid = "330802c5-95bd-11e8-b7ac-acde48001122" resource_instance_id = "f562c2fa-48d3-4798-a723-10209806c068" + reference_graphid = "e3d4505e-bfa7-11e9-b4dc-0242ac160002" + reference_nodeid = "fc3c8080-bfa7-11e9-b4dc-0242ac160002" + person_graphid = "0c6269e8-bfa8-11e9-bd39-0242ac160002" @classmethod def setUpTestData(cls): @@ -314,3 +321,36 @@ def test_crud_allowed_if_no_explicit_permissions(self): self.assertEqual(view.status_code, 200) self.assertEqual(edit.status_code, 200) self.assertEqual(delete.status_code, 200) + + def test_get_related_resource(self): + se = SearchEngineFactory().create() + user = User.objects.get(username="admin") + is_related_to_valueid = "ac41d9be-79db-4256-b368-2f4559cfbe55" + en_preflabel = "is related to" + person_resourceid = "b6754e7a-7f18-40d1-93fe-61763d37d55e" + person_resource = Resource( + graph_id=self.person_graphid, resourceinstanceid=person_resourceid + ) + person_resource.save() + + reference_resourceid = "380b8364-50e6-4f5b-af08-0ea3ab56a406" + reference_resource = Resource( + graph_id=self.reference_graphid, resourceinstanceid=reference_resourceid + ) + reference_resource.save() + reference_tile = Tile.get_blank_tile( + self.reference_nodeid, reference_resourceid + ) + reference_tile.data[self.reference_nodeid] = [ + { + "resourceName": "", + "ontologyProperty": is_related_to_valueid, + "inverseOntologyProperty": is_related_to_valueid, + "resourceId": person_resourceid, + } + ] + reference_tile.save() + sync_es(se) + ret = reference_resource.get_related_resources(user=user) + relationship = ret["resource_relationships"][0]["relationshiptype_label"] + self.assertEqual(relationship, en_preflabel)