Commit 47cf2c46 authored by Sebastien Robin's avatar Sebastien Robin

improve the synchronization so that it should goins faster


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1203 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent de783d41
...@@ -213,7 +213,7 @@ class Conflict(SyncCode, Base): ...@@ -213,7 +213,7 @@ class Conflict(SyncCode, Base):
""" """
return self.keyword return self.keyword
class Signature(SyncCode,Folder): class Signature(Folder,SyncCode):
""" """
status -- SENT, CONFLICT... status -- SENT, CONFLICT...
md5_object -- An MD5 value of a given document md5_object -- An MD5 value of a given document
...@@ -262,6 +262,7 @@ class Signature(SyncCode,Folder): ...@@ -262,6 +262,7 @@ class Signature(SyncCode,Folder):
# XXX This may be a problem, if the document is changed # XXX This may be a problem, if the document is changed
# during a synchronization # during a synchronization
self.setLastSynchronizationDate(DateTime()) self.setLastSynchronizationDate(DateTime())
self.getParent().removeRemainingObject(self.getObject())
if status == self.NOT_SYNCHRONIZED: if status == self.NOT_SYNCHRONIZED:
self.setTempXML(None) self.setTempXML(None)
self.setPartialXML(None) self.setPartialXML(None)
...@@ -497,10 +498,15 @@ class Signature(SyncCode,Folder): ...@@ -497,10 +498,15 @@ class Signature(SyncCode,Folder):
else: else:
self.resetConflictList() self.resetConflictList()
def getObject(self):
"""
Returns the object corresponding to this signature
"""
return self.getParent().getObjectFromGid(self.getGid())
def addSubscription( self, id, title='', REQUEST=None ): def addSubscription( self, id, title='', REQUEST=None ):
""" """
Add a new Category and generate UID by calling the Add a new Subscribption
ZSQLCatalog
""" """
o = Subscription( id ,'','','','','','') o = Subscription( id ,'','','','','','')
self._setObject( id, o ) self._setObject( id, o )
...@@ -509,7 +515,8 @@ def addSubscription( self, id, title='', REQUEST=None ): ...@@ -509,7 +515,8 @@ def addSubscription( self, id, title='', REQUEST=None ):
return o return o
#class Subscription(SyncCode, Implicit): #class Subscription(SyncCode, Implicit):
class Subscription(SyncCode, Implicit, Folder): #class Subscription(Folder, SyncCode, Implicit, Folder, Impli):
class Subscription(Folder, SyncCode):
""" """
Subscription hold the definition of a master ODB Subscription hold the definition of a master ODB
from/to which a selection of objects will be synchronised from/to which a selection of objects will be synchronised
...@@ -960,6 +967,8 @@ class Subscription(SyncCode, Implicit, Folder): ...@@ -960,6 +967,8 @@ class Subscription(SyncCode, Implicit, Folder):
o = None o = None
if gid in self.objectIds(): if gid in self.objectIds():
o = self._getOb(gid) o = self._getOb(gid)
#if o is not None:
# return o.__of__(self)
return o return o
def getSignatureList(self): def getSignatureList(self):
...@@ -998,6 +1007,47 @@ class Subscription(SyncCode, Implicit, Folder): ...@@ -998,6 +1007,47 @@ class Subscription(SyncCode, Implicit, Folder):
conflict_list += signature.getConflictList() conflict_list += signature.getConflictList()
return conflict_list return conflict_list
def getRemainingObjectList(self):
"""
We should now wich objects should still
synchronize
"""
return getattr(self,'remaining_object_list',None)
def setRemainingObjectList(self, value):
"""
We should now wich objects should still
synchronize
"""
setattr(self,'remaining_object_list',value)
def removeRemainingObject(self, object):
"""
We should now wich objects should still
synchronize
"""
remaining_object_list = self.getRemainingObjectList()
if remaining_object_list is not None:
new_list = []
for o in remaining_object_list:
if o != object:
new_list.append(o)
self.setRemainingObjectList(new_list)
# def getCurrentObject(self):
# """
# When we send some partial data, then we should
# always synchronize the same object until it is finished
# """
# getattr(self,'current_object',None)
#
# def setCurrentObject(self,object):
# """
# When we send some partial data, then we should
# always synchronize the same object until it is finished
# """
# setattr(self,'current_object',object)
def startSynchronization(self): def startSynchronization(self):
""" """
Set the status of every object as NOT_SYNCHRONIZED Set the status of every object as NOT_SYNCHRONIZED
...@@ -1009,3 +1059,4 @@ class Subscription(SyncCode, Implicit, Folder): ...@@ -1009,3 +1059,4 @@ class Subscription(SyncCode, Implicit, Folder):
o.setStatus(self.NOT_SYNCHRONIZED) o.setStatus(self.NOT_SYNCHRONIZED)
o.setPartialXML(None) o.setPartialXML(None)
o.setTempXML(None) o.setTempXML(None)
self.setRemainingObjectList(None)
...@@ -874,11 +874,24 @@ class SynchronizationTool( SubscriptionSynchronization, PublicationSynchronizati ...@@ -874,11 +874,24 @@ class SynchronizationTool( SubscriptionSynchronization, PublicationSynchronizati
""" """
return 'sub_' + title return 'sub_' + title
# security.declarePrivate('notify_sync')
# def notify_sync(self, event_type, object, infos):
# """Notification from the event service.
#
# # XXX very specific to cps
#
# Called when an object is added/deleted/modified.
# Update the date of sync
# """
# from Products.CPSCore.utils import _isinstance
# from Products.CPSCore.ProxyBase import ProxyBase
#
# if event_type in ('sys_modify_object',
# 'modify_object'):
# if not(_isinstance(object, ProxyBase)):
# repotool = getToolByName(self, 'portal_repository')
# if repotool.isObjectInRepository(object):
# object_id = object.getId()
InitializeClass( SynchronizationTool ) InitializeClass( SynchronizationTool )
...@@ -556,7 +556,29 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -556,7 +556,29 @@ class XMLSyncUtilsMixin(SyncCode):
local_gid_list = [] local_gid_list = []
syncml_data = '' syncml_data = ''
for object in domain.getObjectList(): if subscriber.getRemainingObjectList() is None:
object_list = domain.getObjectList()
subscriber.setRemainingObjectList(object_list)
#object_gid = domain.getGidFromObject(object)
local_gid_list = map(lambda x: domain.getGidFromObject(x),object_list)
# Objects to remove
#for object_id in id_list:
for object_gid in subscriber.getGidList():
if not (object_gid in local_gid_list):
# This is an object to remove
signature = subscriber.getSignature(object_gid)
if signature.getStatus()!=self.PARTIAL: # If partial, then we have a signature
# but no local object
xml_object = signature.getXML()
if xml_object is not None: # This prevent to delete an object that we
# were not able to create
syncml_data += self.deleteXMLObject(xml_object=signature.getXML() or '',
object_gid=object_gid,cmd_id=cmd_id)
#for object in domain.getObjectList():
for object in subscriber.getRemainingObjectList():
status = self.SENT status = self.SENT
#gid_generator = getattr(object,domain.getGidGenerator(),None) #gid_generator = getattr(object,domain.getGidGenerator(),None)
object_gid = domain.getGidFromObject(object) object_gid = domain.getGidFromObject(object)
...@@ -701,20 +723,6 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -701,20 +723,6 @@ class XMLSyncUtilsMixin(SyncCode):
elif signature.getAction()=='Add': elif signature.getAction()=='Add':
syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object,gid=object_gid, syncml_data += self.addXMLObject(cmd_id=cmd_id, object=object,gid=object_gid,
xml_string=xml_string, more_data=more_data) xml_string=xml_string, more_data=more_data)
# Objects to remove
#for object_id in id_list:
for object_gid in subscriber.getGidList():
if not (object_gid in local_gid_list):
# This is an object to remove
signature = subscriber.getSignature(object_gid)
if signature.getStatus()!=self.PARTIAL: # If partial, then we have a signature
# but no local object
xml_object = signature.getXML()
if xml_object is not None: # This prevent to delete an object that we
# were not able to create
syncml_data += self.deleteXMLObject(xml_object=signature.getXML() or '',
object_gid=object_gid,cmd_id=cmd_id)
return (syncml_data,xml_confirmation,cmd_id) return (syncml_data,xml_confirmation,cmd_id)
def applyActionList(self, domain=None, subscriber=None,destination_path=None, def applyActionList(self, domain=None, subscriber=None,destination_path=None,
...@@ -736,7 +744,8 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -736,7 +744,8 @@ class XMLSyncUtilsMixin(SyncCode):
object_gid = self.getActionId(next_action) object_gid = self.getActionId(next_action)
signature = subscriber.getSignature(object_gid) signature = subscriber.getSignature(object_gid)
if signature == None: if signature == None:
signature = Signature(gid=object_gid,status=self.NOT_SYNCHRONIZED) LOG('applyActionList, signature is None',0,signature)
signature = Signature(gid=object_gid,status=self.NOT_SYNCHRONIZED).__of__(subscriber)
subscriber.addSignature(signature) subscriber.addSignature(signature)
force = signature.getForce() force = signature.getForce()
object = domain.getObjectFromGid(object_gid) object = domain.getObjectFromGid(object_gid)
......
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