Commit c803a430 authored by Tatuya Kamada's avatar Tatuya Kamada

Add a method to update the persistent id_dict from portal_ids table.

This method is intended to use when we are disabled 'Store in the ZODB'
or set a big number as the 'Store interval', but at the same time we need to
update the persistent dict from the fresh portal_ids table at a certain point.

This method needs a unit test.
parent ed8dac90
......@@ -282,3 +282,27 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
portal.IdTool_zDropTable()
portal.IdTool_zCreateEmptyTable()
self._updateSqlTable()
security.declareProtected(Permissions.ModifyPortalContent,
'updateLastMaxIdDictFromTable')
def updateLastMaxIdDictFromTable(self):
"""
Update the Persistent id_dict from portal_ids table.
Warning: IdToool_zGetValueList ZSQL method retrieve all the records of
portal_ids table. So this method neither does not scale well if you have
millions id_group.
"""
portal = self.getPortalObject()
get_value_list = portal.IdTool_zGetValueList
new_id_dict = dict()
for line in get_value_list().dictionaries():
id_group = line['id_group']
last_id = line['last_id']
if isinstance(last_id, int) or isinstance(last_id, long):
new_id_dict[id_group] = ScalarMaxConflictResolver(last_id)
else:
raise TypeError, 'the value in the dictionary given is not a number'
if self.last_max_id_dict is None:
self.last_max_id_dict = PersistentMapping()
self.last_max_id_dict.update(new_id_dict)
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