-
Notifications
You must be signed in to change notification settings - Fork 144
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
11583 leverage cache for related resource relationship preflabel lookup #11584
base: dev/7.6.x
Are you sure you want to change the base?
Conversation
This seems like a nice performance fix, but something for v8 rather than 7.6. |
The issue isn't whether or not it addresses a bug, but whether it fixes bug that: causes the system to crash, causes data loss, is a regression since 7.5, is a security vulnerability, or is in a new 7.6.0 feature. A performance fix can be justified if it addresses one of those concerns (generally if the system will crash without the fix). #11576 and #11572 are examples. |
arches/app/models/resource.py
Outdated
if f'{relation["relationshiptype"]}{lang}' not in preflabel_lookup: | ||
preflabel_lookup[f'{relation["relationshiptype"]}{lang}'] = ( | ||
get_preflabel_from_valueid( | ||
relation["relationshiptype"], lang | ||
) | ||
) | ||
preflabel = preflabel_lookup[ | ||
f'{relation["relationshiptype"]}{lang}' | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this were reordered a bit, there wouldn't be a need to check the dictionary for the value twice (once to check if the value is not in the preflable_lookup and a second time to retrieve it):
try:
preflabel = preflabel_lookup[f'{relation["relationshiptype"]}{lang}']
except KeyError:
preflabel = get_preflabel_from_valueid(relation["relationshiptype"], lang)
preflabel_lookup[f'{relation["relationshiptype"]}{lang}'] = preflabel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this code below:
relation["relationshiptype_label"] = preflabel["value"] or ""
except:
relation["relationshiptype_label"] = (
relation["relationshiptype"] or ""
)
while there's some ambiguity as to which exceptions it was meant to handle, at a minimum there's an anticipation that either preflabel["value"]
could raise an error (KeyError
?) or that relation["relationshiptype"]
is None
(causing perhaps an ES 404 error downstream in get_preflabel_from_valueid
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you check the bottom of this trace, you'll see the original KeyError
reproduced that the original except
was meant to handle, as one outcome
Internal Server Error: /resource/related/b6d2d1e1-9db8-4787-92ca-048b34bf6d66
Traceback (most recent call last):
File "/Users/galenmancino/repos/arches/arches/app/models/resource.py", line 905, in get_related_resources
preflabel = preflabel_lookup[f'{relation["relationshiptype"]}{lang}']
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'Noneen'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/galenmancino/repos/venv_312_arches7.6/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/galenmancino/repos/venv_312_arches7.6/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/galenmancino/repos/venv_312_arches7.6/lib/python3.12/site-packages/django/views/generic/base.py", line 104, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/galenmancino/repos/venv_312_arches7.6/lib/python3.12/site-packages/django/utils/decorators.py", line 46, in _wrapper
return bound_method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/galenmancino/repos/arches/arches/app/utils/decorators.py", line 109, in wrapper
return function(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/galenmancino/repos/venv_312_arches7.6/lib/python3.12/site-packages/django/views/generic/base.py", line 143, in dispatch
return handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/galenmancino/repos/arches/arches/app/views/resource.py", line 1064, in get
ret = resource.get_related_resources(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/galenmancino/repos/arches/arches/app/models/resource.py", line 908, in get_related_resources
preflabel = get_preflabel_from_valueid(relation["relationshiptype"], lang)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/galenmancino/repos/arches/arches/app/models/concept.py", line 1734, in get_preflabel_from_valueid
if concept_label["found"]:
~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'found'
…ed_resources, re #11583
Types of changes
Description of Change
significant speedup, addresses #11583 however it might even warrant a separate PR to just lookup the preflabels in bulk but the underlying logic is a bit more complex for that approach
Issues Solved
addresses #11583
Checklist
Accessibility Checklist
Developer Guide
Ticket Background
Further comments