Skip to content

Commit

Permalink
Performance: prioritize raw getter for AllowedInstruments field (sena…
Browse files Browse the repository at this point in the history
…ite#2148)

* Performance: prioritize raw getter for AllowedInstruments field

* Do not wakeup instrument unless strictly necessary

* Extract the UIDs of method instruments for proper comparison

* Remove whitespace

* Retrieval of full objects is recommended sometimes

* Simplify getRawInstrument function

* Remove unnecessary fallback to list
  • Loading branch information
xispa committed Sep 27, 2022
1 parent 55d0fbd commit 6d4760e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
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)
------------------

- #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
- #2145 Crop page navigation for DX reference widget
Expand Down
8 changes: 4 additions & 4 deletions src/bika/lims/browser/analyses/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1532,13 +1532,13 @@ def is_instrument_required(self, analysis):
# If method selection list is required, the instrument selection too
if self.is_method_required(analysis):
return True

# Always return true if the analysis has an instrument assigned
if self.get_instrument(analysis):
analysis = self.get_object(analysis)
if analysis.getRawInstrument():
return True

obj = self.get_object(analysis)
instruments = obj.getAllowedInstruments()
instruments = analysis.getRawAllowedInstruments()
# There is no need to check for the instruments of the method assigned
# to # the analysis (if any), because the instruments rendered in the
# selection list are always a subset of the allowed instruments when
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 @@ -728,7 +728,7 @@ def isInstrumentAllowed(self, instrument):
:rtype: bool
"""
uid = api.get_uid(instrument)
return uid in map(api.get_uid, self.getAllowedInstruments())
return uid in self.getRawAllowedInstruments()

@security.public
def isMethodAllowed(self, method):
Expand Down Expand Up @@ -768,6 +768,15 @@ def getAllowedInstruments(self):
return []
return service.getInstruments()

@security.public
def getRawAllowedInstruments(self):
"""Returns the UIDS of the allowed instruments from the service
"""
service = self.getAnalysisService()
if not service:
return []
return service.getRawInstruments()

@security.public
def getExponentialFormatPrecision(self, result=None):
""" Returns the precision for the Analysis Service and result
Expand Down
6 changes: 1 addition & 5 deletions src/bika/lims/content/abstractbaseanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,11 +963,7 @@ def getRawInstrument(self):
:returns: Instrument UID
"""
field = self.getField("Instrument")
instrument = field.getRaw(self)
if not instrument:
return None
return instrument
return self.getField("Instrument").getRaw(self)

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

0 comments on commit 6d4760e

Please sign in to comment.