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

Performance: prioritize raw getter for AllowedMethods field #2149

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -5,6 +5,7 @@ Changelog
2.3.0 (unreleased)
------------------

- #2150 Performance: prioritize raw getter for AllowedMethods field
- #2148 Performance: prioritize raw getter for AllowedInstruments field
- #2147 Remove stale function workflow.getReviewHistory
- #2146 Fix "No object found for UID: <laboratory_uid>" in report preview
Expand Down
4 changes: 2 additions & 2 deletions src/bika/lims/browser/analyses/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,11 +1516,11 @@ def is_method_required(self, analysis):
"""
# Always return true if the analysis has a method assigned
obj = self.get_object(analysis)
method = obj.getMethod()
method = obj.getRawMethod()
if method:
return True

methods = obj.getAllowedMethods()
methods = obj.getRawAllowedMethods()
return len(methods) > 0

def is_instrument_required(self, analysis):
Expand Down
11 changes: 10 additions & 1 deletion src/bika/lims/content/abstractanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def isMethodAllowed(self, method):
:rtype: bool
"""
uid = api.get_uid(method)
return uid in map(api.get_uid, self.getAllowedMethods())
return uid in self.getRawAllowedMethods()

@security.public
def getAllowedMethods(self):
Expand All @@ -756,6 +756,15 @@ def getAllowedMethods(self):
# get the available methods of the service
return service.getMethods()

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

@security.public
def getAllowedInstruments(self):
"""Returns the allowed instruments from the service
Expand Down
7 changes: 2 additions & 5 deletions src/bika/lims/content/analysisservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,14 @@ def getMethods(self):

:returns: List of method objects
"""
field = self.getField("Methods")
methods = field.get(self)
return methods
return self.getField("Methods").get(self)

def getRawMethods(self):
"""Returns the assigned method UIDs

:returns: List of method UIDs
"""
methods = self.getMethods()
return map(api.get_uid, methods)
return self.getField("Methods").getRaw(self)

def getMethod(self):
"""Get the default method
Expand Down