Skip to content

Commit

Permalink
Performance: prioritize raw getter for AllowedMethods field (#2149 po…
Browse files Browse the repository at this point in the history
…rt) (#2320)

* Optimize the retrieval of method uids from abstractanalysis

* Leave get_object_by_uid unchanged

* Changelog
  • Loading branch information
xispa authored Jun 5, 2023
1 parent c942cba commit 706689d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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)
------------------

- #2320 Performance: prioritize raw getter for AllowedMethods field (#2149 port)
- #2308 Rely on fields when validating values on sample creation (#2307 port)
- #2249 Fix APIError: None is not supported (upgrade 1.3.6)
- #2198 Use portal as relative path for sticker icons (#2197 port)
Expand Down
19 changes: 15 additions & 4 deletions bika/lims/content/abstractanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def isMethodAllowed(self, method):
:rtype: bool
"""
uid = api.get_uid(method)
return uid in self.getAllowedMethodUIDs()
return uid in self.getRawAllowedMethods()

@security.public
def getAllowedMethods(self):
Expand All @@ -718,17 +718,28 @@ def getAllowedMethods(self):
:return: A list with the methods allowed for this analysis
:rtype: list of Methods
"""
uids = self.getRawAllowedMethods()
objs = [api.get_object_by_uid(uid, default=None) for uid in uids]
return filter(None, objs)

@security.public
def getRawAllowedMethods(self):
"""Returns the UIDs of the allowed methods for this analysis
"""
service = self.getAnalysisService()
if not service:
return []

methods = []
if self.getManualEntryOfResults():
methods = service.getMethods()
methods = service.getRawMethods()[:]

if self.getInstrumentEntryOfResults():
for instrument in service.getInstruments():
methods.extend(instrument.getMethods())
instrument_methods = instrument.getRawMethods()[:]
methods.extend(instrument_methods)

methods = filter(api.is_uid, methods)
return list(set(methods))

@security.public
Expand All @@ -738,7 +749,7 @@ def getAllowedMethodUIDs(self):
:return: A list with the UIDs of the methods allowed for this analysis
:rtype: list of strings
"""
return [m.UID() for m in self.getAllowedMethods()]
return self.getRawAllowedMethods()

@security.public
def getAllowedInstruments(self):
Expand Down

0 comments on commit 706689d

Please sign in to comment.