Commit a0d61569 authored by Vincent Pelletier's avatar Vincent Pelletier

erp5_full_text_mroonga_catalog: Inherit priority.

Spawn fulltext indexation activity with the same priority as the
top-priority activity part of current activity group.
And expose the priority of current activity (top-priority for grouped
activities).
Ideally, the priority of each spawned activity should be the top-priority
of all activities member of this activity group for corresponding document.
But there is no obvious way to achieve that through indexation API without
increasing complexity significantly.
parent c502e47c
# This script is called to defer fulltext indexing in a lower priority. # This script is called to defer fulltext indexing.
METHOD_ID = script.id + 'Activity' METHOD_ID = script.id + 'Activity'
GROUP_METHOD_ID = context.getPath() + '/' + METHOD_ID GROUP_METHOD_ID = context.getPath() + '/' + METHOD_ID
activateObject = context.getPortalObject().portal_activities.activateObject activateObject = context.getPortalObject().portal_activities.activateObject
try:
priority = context.getActivityRuntimeEnvironment().getPriority()
except KeyError:
# called outside of an activity, could be an immediate reindexation
# XXX: duplicates default priority for sake of simplicity and speed.
# Strictly, this could also look-up default activate parameters, but on
# which document ? Traversing is expensive. So keep things fast by default.
priority = 1
for document, root_document_path in zip(getPath, getRootDocumentPath): for document, root_document_path in zip(getPath, getRootDocumentPath):
getattr( getattr(
activateObject( activateObject(
document, document,
activity='SQLDict', activity='SQLDict',
priority=4, priority=priority,
node='same', node='same',
group_method_id=GROUP_METHOD_ID, group_method_id=GROUP_METHOD_ID,
serialization_tag='full_text_' + root_document_path, serialization_tag='full_text_' + root_document_path,
......
...@@ -631,7 +631,10 @@ CREATE TABLE %s ( ...@@ -631,7 +631,10 @@ CREATE TABLE %s (
method = activity_tool.invokeGroup method = activity_tool.invokeGroup
args = (group_method_id, message_list, self.__class__.__name__, args = (group_method_id, message_list, self.__class__.__name__,
hasattr(self, 'generateMessageUID')) hasattr(self, 'generateMessageUID'))
activity_runtime_environment = ActivityRuntimeEnvironment(None) activity_runtime_environment = ActivityRuntimeEnvironment(
None,
priority=min(x.line.priority for x in message_list),
)
else: else:
method = activity_tool.invoke method = activity_tool.invoke
message, = message_list message, = message_list
......
...@@ -41,8 +41,9 @@ class BaseMessage: ...@@ -41,8 +41,9 @@ class BaseMessage:
class ActivityRuntimeEnvironment(object): class ActivityRuntimeEnvironment(object):
security = ClassSecurityInfo() security = ClassSecurityInfo()
def __init__(self, message): def __init__(self, message, priority=None):
self._message = message self._message = message
self._priority = priority
def __enter__(self): def __enter__(self):
assert not hasattr(_activity_runtime_environment, 'value') assert not hasattr(_activity_runtime_environment, 'value')
...@@ -56,6 +57,13 @@ class ActivityRuntimeEnvironment(object): ...@@ -56,6 +57,13 @@ class ActivityRuntimeEnvironment(object):
def getTag(self, default=None): def getTag(self, default=None):
return self._message.activity_kw.get('tag', default) return self._message.activity_kw.get('tag', default)
security.declarePublic('getPriority')
def getPriority(self):
result = self._priority
if result is None:
return self._message.line.priority
return result
security.declarePublic('edit') security.declarePublic('edit')
def edit(self, **kw): def edit(self, **kw):
# There is no point allowing to modify other attributes from a message # There is no point allowing to modify other attributes from a message
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment