Skip to content

Commit

Permalink
11583 leverage cache for related resource relationship preflabel look…
Browse files Browse the repository at this point in the history
…up (#11584)

* cache already looked up relationship preflabels in Resource.get_related_resources, re #11583
* add release note, re #11583
  • Loading branch information
whatisgalen authored Nov 15, 2024
1 parent 51e50ab commit 429603e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
16 changes: 13 additions & 3 deletions arches/app/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"] = (
Expand Down
1 change: 1 addition & 0 deletions releases/7.6.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
1 change: 1 addition & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
42 changes: 41 additions & 1 deletion tests/views/resource_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit 429603e

Please sign in to comment.