Commit 5a4407f0 authored by Aurel's avatar Aurel

use generic recursiveCallMethod to implement reset of signature

Thanks to vincent for notifying
parent cc1c0d84
...@@ -284,9 +284,18 @@ class SyncMLSignature(XMLObject): ...@@ -284,9 +284,18 @@ class SyncMLSignature(XMLObject):
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'reset') 'reset')
def reset(self): def reset(self, no_conflict=False):
"""Clear Signature and change validation_state to not_synchronized """
""" Clear Signature and change validation_state to not_synchronized
no_conflict : prevent the reset of signature for which conflict
has not been marked resolved, this is usefull when
resetting all signature at the beginning of a sync process
"""
if no_conflict and self.getValidationState() in (
'conflict',
'conflict_resolved_with_merge',
'conflict_resolved_with_client_command_winning'):
return
if self.getValidationState() != 'not_synchronized': if self.getValidationState() != 'not_synchronized':
self.drift() self.drift()
self.setPartialData(None) self.setPartialData(None)
......
...@@ -991,46 +991,14 @@ class SyncMLSubscription(XMLObject): ...@@ -991,46 +991,14 @@ class SyncMLSubscription(XMLObject):
'conflict_resolved_with_client_command_winning'): 'conflict_resolved_with_client_command_winning'):
signature.reset() signature.reset()
def _resetSignatureIDList(self, signature_id_list):
"""
Reset a list of signature given by their ids
"""
for signature_id in signature_id_list:
signature = self[signature_id]
if signature.getValidationState() not in (
'conflict',
'conflict_resolved_with_merge',
'conflict_resolved_with_client_command_winning'):
signature.reset()
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'getAndActivateResetSignature') 'getAndActivateResetSignature')
def getAndActivateResetSignature(self, min_packet_id=0): def getAndActivateResetSignature(self, min_packet_id=0):
""" """
Reset signature by packet (i.e. getAndActivate) Reset signature by packet (i.e. getAndActivate)
""" """
activate_kw = {"activity" : "SQLQueue", self.recurseCallMethod(method_id="reset",
"priority" : ACTIVITY_PRIORITY} method_kw = {"no_conflict" : True},
packet_size = 30 min_depth=1,
limit = packet_size * 100 max_depth=1,
activate = self.activate activate_kw={'priority': ACTIVITY_PRIORITY})
callback_method = getattr(activate(**activate_kw), "_resetSignatureIDList")
signature_id_list = self.objectIds()
id_length = len(self)
# Either there will be remaining id, either this is the end
max_packet = min(min_packet_id+limit, len(self))
for i in xrange(min_packet_id, max_packet, packet_size):
# syncml_logger.info("getAndActivateResetSignature : call callback method")
callback_method(
signature_id_list=list(signature_id_list[i:i+packet_size]))
min_packet_id += limit # Next point to start to read the id_list
if id_length > min_packet_id:
# syncml_logger.info("getAndActivateResetSignature : calling itself recursively %s"
# % (min_packet_id))
activate(activity="SQLQueue",
priority=ACTIVITY_PRIORITY+1).getAndActivateResetSignature(
min_packet_id=min_packet_id)
...@@ -454,8 +454,7 @@ class EngineMixin(object): ...@@ -454,8 +454,7 @@ class EngineMixin(object):
subscriber.activate( subscriber.activate(
activity="SQLQueue", activity="SQLQueue",
after_method_id_list=("reset", after_method_id_list=("reset",
"getAndActivateResetSignature", "_recurseCallMethod"),
"_resetSignatureIDList"),
# Wait for all reset to be done # Wait for all reset to be done
# before starting sync # before starting sync
priority=ACTIVITY_PRIORITY, priority=ACTIVITY_PRIORITY,
......
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