Skip to content
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

Improve performance of legacy AT UIDReferenceField's getter (#2212 port) #2324

Merged
merged 23 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6a18074
Optimize the retrieval of method uids from abstractanalysis
xispa Jun 3, 2023
991b735
Improve the createion process of AT content types
xispa Jun 3, 2023
20300a7
Cleanup get*UID functions to prevent unnecessary searches and instant…
xispa Jun 3, 2023
4299a8d
Remove default_method from AnalysisRequest's Contact field
xispa Jun 3, 2023
780e3c9
Migrate AnalysisRequest's ReferenceField fields to UIDReferenceField
xispa Jun 4, 2023
6bfcc67
Merge branch '1.3.x' of github.com:senaite/senaite.core into port-2149
xispa Jun 5, 2023
4b5de0b
Leave get_object_by_uid unchanged
xispa Jun 5, 2023
3893695
Changelog
xispa Jun 5, 2023
1736c5e
Merge branch '1.3.x' of github.com:senaite/senaite.core into port-2163
xispa Jun 5, 2023
92fdd7f
Merge branch 'port-2149' into port-2163
xispa Jun 5, 2023
f4f09fa
Use api.get_object_by_uid with default value instead of get_object
xispa Jun 5, 2023
487c19d
Merge branch '1.3.x' of github.com:senaite/senaite.core into port-2150
xispa Jun 5, 2023
2b7eb1e
Merge branch 'port-2149' into port-2150
xispa Jun 5, 2023
4dac034
Changelog
xispa Jun 5, 2023
dc4678e
Merge branch 'port-2150' into port-2163
xispa Jun 5, 2023
aa16258
Changelog
xispa Jun 5, 2023
dd2896e
Merge branch 'port-2163' into port-2208
xispa Jun 5, 2023
de7e3cd
Changelog
xispa Jun 5, 2023
09a8202
Merge branch 'port-2208' into port-2209
xispa Jun 5, 2023
35a5d0d
Changelog
xispa Jun 5, 2023
f3b4d6e
Remove Profile field (stale) from AnalysisRequest
xispa Jun 5, 2023
9ec5000
Improve performance of legacy AT `UIDReferenceField`'s getter (#2212 …
xispa Jun 5, 2023
ddb7d56
Merge branch '1.3.x' into port-2212
ramonski Jun 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
1.3.6 (unreleased)
------------------

- #2324 Migrate AnalysisRequest's ReferenceField to UIDReferenceField (#2209 port)
- #2323 Remove default_method from AnalysisRequest's Contact field (#2208 port)
- #2322 Cleanup getUID functions to prevent unnecessary searches (#2163 port)
- #2321 Improve the creation process of AT content types (#2150 port)
Expand Down
31 changes: 20 additions & 11 deletions bika/lims/browser/fields/uidreferencefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,27 @@ def get(self, context, **kwargs):
:return: object or list of objects for multiValued fields.
:rtype: BaseContent | list[BaseContent]
"""
value = StringField.get(self, context, **kwargs)
if not value:
return [] if self.multiValued else None
uids = StringField.get(self, context, **kwargs)
if not isinstance(uids, list):
uids = [uids]

# Do a direct search for all brains at once
uc = api.get_tool("uid_catalog")
references = uc(UID=uids)

# Keep the original order of items
references = sorted(references, key=lambda it: uids.index(it.UID))

# Return objects by default
full_objects = kwargs.pop("full_objects", True)
if full_objects:
references = [api.get_object(ref) for ref in references]

if self.multiValued:
# Only return objects which actually exist; this is necessary here
# because there are no HoldingReferences. This opens the
# possibility that deletions leave hanging references.
ret = filter(
lambda x: x, [self.get_object(context, uid) for uid in value])
else:
ret = self.get_object(context, value)
return ret
return references
elif references:
return references[0]
return None

@security.public
def getRaw(self, context, aslist=False, **kwargs):
Expand Down
Loading