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 optimizations in Analysis Request creation #237

Merged
merged 4 commits into from
Aug 30, 2017
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
9 changes: 5 additions & 4 deletions bika/lims/browser/js/bika.lims.analysisrequest.add_by_col.js
Original file line number Diff line number Diff line change
Expand Up @@ -1773,10 +1773,11 @@ function AnalysisRequestAddByCol() {
// Expand category
var service = service_data[si]
services.push(service)
var th = $("table[form_id='" + service['PointOfCapture'] + "'] " +
"th[cat='" + service['CategoryTitle'] + "']")
if(expanded_categories.indexOf(th) < 0) {
expanded_categories.push(th)
var th_key = "table[form_id='" + service['PointOfCapture'] + "'] " +
"th[cat='" + service['CategoryTitle'] + "']"
var th = $(th_key)
if(expanded_categories.indexOf(th_key) < 0) {
expanded_categories.push(th_key)
var def = $.Deferred()
def = category_header_expand_handler(th)
defs.push(def)
Expand Down
27 changes: 18 additions & 9 deletions bika/lims/content/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,6 @@
showOn=True,
),
),
ComputedField(
'BatchUID',
expression='here.getBatch().UID() if here.getBatch() else ""',
widget=ComputedWidget(
visible=False,
),
),
ReferenceField(
'SamplingRound',
allowed_types=('SamplingRound',),
Expand Down Expand Up @@ -1861,6 +1854,7 @@ def getProvince(self):
client = self.aq_parent
return client.getProvince()

@security.public
def getBatch(self):
# The parent type may be "Batch" during ar_add.
# This function fills the hidden field in ar_add.pt
Expand All @@ -1869,6 +1863,19 @@ def getBatch(self):
else:
return self.Schema()['Batch'].get(self)

@security.public
def getBatchUID(self):
batch = self.getBatch()
if batch:
return batch.UID()

@security.public
def setBatch(self, value=None):
original_value = self.Schema().getField('Batch').get(self)
if original_value != value:
self.Schema().getField('Batch').set(self, value)
self._reindexAnalyses(['getBatchUID'], False)

def getDefaultMemberDiscount(self):
""" compute default member discount if it applies """
if hasattr(self, 'getMemberDiscountApplies'):
Expand Down Expand Up @@ -2985,8 +2992,10 @@ def getPrioritySortkey(self):
def setPriority(self, value):
if not value:
value = self.Schema().getField('Priority').getDefault(self)
self.Schema().getField('Priority').set(self, value)
self._reindexAnalyses(['getPrioritySortkey'], True)
original_value = self.Schema().getField('Priority').get(self)
if original_value != value:
self.Schema().getField('Priority').set(self, value)
self._reindexAnalyses(['getPrioritySortkey'], True)

@security.private
def _reindexAnalyses(self, idxs=None, update_metadata=False):
Expand Down
12 changes: 0 additions & 12 deletions bika/lims/subscribers/objectmodified.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,3 @@ def ObjectModifiedEventHandler(obj, event):
brains = cat(portal_type=i[0], getCategoryUID=obj.UID())
for brain in brains:
brain.getObject().reindexObject(idxs=['getCategoryTitle'])
# TODO: This is a workaround in order to reindex the getBatchUID index
# of analyses when the analysis request has been modified. When the
# ReferenceField 'batch' is modified (and because it is reference field)
# only the archetype 'Reference' object is flagged as modified, not
# the whole AnalysisRequest. We need to migrate that reference field
# to the new ones.
# For now, we will take advantage of that reference object and we will
# reindex only the getbatchUID.
elif IAnalysisRequest.providedBy(obj.aq_parent.aq_inner):
analyses = obj.getAnalyses()
for analysis in analyses:
analysis.getObject().reindexObject(idxs=['getBatchUID'])
17 changes: 7 additions & 10 deletions bika/lims/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def doActionFor(instance, action_id, active_only=True, allowed_transition=True):
workflow = getToolByName(instance, "portal_workflow")
skipaction = skip(instance, action_id, peek=True)
if skipaction:
clazzname = instance.__class__.__name__
msg = "Skipping transition '{0}': {1} '{2}'".format(action_id,
clazzname,
instance.getId())
logger.info(msg)
#clazzname = instance.__class__.__name__
#msg = "Skipping transition '{0}': {1} '{2}'".format(action_id,
# clazzname,
# instance.getId())
#logger.info(msg)
return actionperformed, message

if allowed_transition:
Expand Down Expand Up @@ -319,11 +319,8 @@ def wasTransitionPerformed(instance, transition_id):
"""Checks if the transition has already been performed to the object
Instance's workflow history is checked.
"""
review_history = getReviewHistory(instance)
for event in review_history:
if event['action'] == transition_id:
return True
return False
transitions = getReviewHistoryActionsList(instance)
return transition_id in transitions


def isActive(instance):
Expand Down