Skip to content

Commit bb5fa7e

Browse files
xisparamonski
andauthored
Performance: prioritize raw getter for AllowedMethods field (senaite#2149)
Co-authored-by: Ramon Bartl <[email protected]>
1 parent 6d4760e commit bb5fa7e

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55
2.3.0 (unreleased)
66
------------------
77

8+
- #2150 Performance: prioritize raw getter for AllowedMethods field
89
- #2148 Performance: prioritize raw getter for AllowedInstruments field
910
- #2147 Remove stale function workflow.getReviewHistory
1011
- #2146 Fix "No object found for UID: <laboratory_uid>" in report preview

src/bika/lims/browser/analyses/view.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1516,11 +1516,11 @@ def is_method_required(self, analysis):
15161516
"""
15171517
# Always return true if the analysis has a method assigned
15181518
obj = self.get_object(analysis)
1519-
method = obj.getMethod()
1519+
method = obj.getRawMethod()
15201520
if method:
15211521
return True
15221522

1523-
methods = obj.getAllowedMethods()
1523+
methods = obj.getRawAllowedMethods()
15241524
return len(methods) > 0
15251525

15261526
def is_instrument_required(self, analysis):

src/bika/lims/content/abstractanalysis.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def isMethodAllowed(self, method):
739739
:rtype: bool
740740
"""
741741
uid = api.get_uid(method)
742-
return uid in map(api.get_uid, self.getAllowedMethods())
742+
return uid in self.getRawAllowedMethods()
743743

744744
@security.public
745745
def getAllowedMethods(self):
@@ -756,6 +756,15 @@ def getAllowedMethods(self):
756756
# get the available methods of the service
757757
return service.getMethods()
758758

759+
@security.public
760+
def getRawAllowedMethods(self):
761+
"""Returns the UIDs of the allowed methods for this analysis
762+
"""
763+
service = self.getAnalysisService()
764+
if not service:
765+
return []
766+
return service.getRawMethods()
767+
759768
@security.public
760769
def getAllowedInstruments(self):
761770
"""Returns the allowed instruments from the service

src/bika/lims/content/analysisservice.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,14 @@ def getMethods(self):
315315
316316
:returns: List of method objects
317317
"""
318-
field = self.getField("Methods")
319-
methods = field.get(self)
320-
return methods
318+
return self.getField("Methods").get(self)
321319

322320
def getRawMethods(self):
323321
"""Returns the assigned method UIDs
324322
325323
:returns: List of method UIDs
326324
"""
327-
methods = self.getMethods()
328-
return map(api.get_uid, methods)
325+
return self.getField("Methods").getRaw(self)
329326

330327
def getMethod(self):
331328
"""Get the default method

0 commit comments

Comments
 (0)