Skip to content

Commit

Permalink
Improve performance of analysis verification (#2643)
Browse files Browse the repository at this point in the history
* Add verification check

* Omit the current processed analysis from the check

* Changelog updated

* Count the length correctly

* Skip reference/duplicates

* docstring added

* Integrate transition chain shortcut

* Removed UID lookup from chains
  • Loading branch information
ramonski authored Nov 26, 2024
1 parent 9538a48 commit 3858edd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
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
2.6.0 (unreleased)
------------------

- #2643 Improve performance of analysis verification
- #2645 Tabbed content view
- #2624 Added "Maximum holding time" setting to services and analyses
- #2637 Do not remove inactive services from profiles and templates
Expand Down
41 changes: 40 additions & 1 deletion src/bika/lims/workflow/analysis/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from bika.lims.interfaces.analysis import IRequestAnalysis
from bika.lims.utils.analysis import create_retest
from bika.lims.workflow import doActionFor
from bika.lims.workflow.analysis import STATE_REJECTED
from bika.lims.workflow.analysis import STATE_RETRACTED
from DateTime import DateTime
from zope.interface import alsoProvides

Expand Down Expand Up @@ -229,7 +231,7 @@ def after_verify(analysis):
ws.reindexObject()

# Promote transition to Analysis Request if Sample auto-verify is enabled
if IRequestAnalysis.providedBy(analysis):
if IRequestAnalysis.providedBy(analysis) and check_all_verified(analysis):
setup = api.get_setup()
if setup.getAutoVerifySamples():
doActionFor(analysis.getRequest(), "verify")
Expand All @@ -238,6 +240,43 @@ def after_verify(analysis):
reindex_request(analysis)


def check_all_verified(analysis):
"""Checks if all analyses are verified
NOTE: This check is provided solely for performance reasons of the `verify`
transition, because it is a less expensive calculation than executing the
`doActionFor` method on the sample for each verified analysis.
The worst case that can happen is that the sample does not get
automatically verified and needs to be transitioned manually.
:param analysis: The current verified analysis
:returns: True if all other routine analyses of the sample are verified
"""

parent = api.get_parent(analysis)
sample = analysis.getRequest()
uid = api.get_uid(analysis)

def is_valid(an):
state = api.get_review_status(an)
return state not in [STATE_REJECTED, STATE_RETRACTED]

# get all *valid* analyses of the sample
analyses = filter(is_valid, sample.getAnalyses())
# get all *verified* analyses of the sample
verified = sample.getAnalyses(object_provides=IVerified.__identifier__)

# NOTE: We remove the current processed routine analysis (if not a WS
# duplicate/reference analysis), because it is either not yet
# verified or processed already in multi-verify scenarios.
if sample == parent:
analyses = filter(lambda x: api.get_uid(x) != uid, analyses)
verified = filter(lambda x: api.get_uid(x) != uid, verified)

return len(analyses) == len(verified)


def after_publish(analysis):
"""Function triggered after a "publish" transition is performed.
"""
Expand Down

0 comments on commit 3858edd

Please sign in to comment.