From fcac8d86b0279ccff90abcf218f2f145de1e94d7 Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Wed, 8 Dec 2010 14:03:28 +0000
Subject: [PATCH] SQLNonContinuousIncreasingIdGenerator: small optimization

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41230 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../SQLNonContinuousIncreasingIdGenerator.py  | 27 +++++++++----------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/product/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py b/product/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py
index 98eea03fc7..a9b1c2923d 100644
--- a/product/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py
+++ b/product/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py
@@ -95,21 +95,20 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
         # If the dictionary not exist, initialize the generator
         self.initializeGenerator()
         last_max_id_dict = self.last_max_id_dict
-      if last_max_id_dict.get(id_group, None) is not None and \
-          last_max_id_dict[id_group].value > new_id:
-        raise ValueError, 'The last_id %s stored in zodb dictionary is ' \
-            'higher than the new id %s generated for id_group %s. ' \
-            'invoke %s/rebuildSqlTable to fix this problem.' % \
-            (last_max_id_dict[id_group].value, new_id, id_group, self.absolute_url())
-      # Check the store interval to store the data
-      store_interval = self.getStoreInterval()
-      if not store_interval:
-        store_interval = 1
-      # Store the new id
-      if last_max_id_dict.get(id_group, None) is None:
+      last_max_id = last_max_id_dict.get(id_group)
+      if last_max_id is None:
         last_max_id_dict[id_group] = ScalarMaxConflictResolver(new_id)
-      elif last_max_id_dict[id_group].value <= (new_id - store_interval):
-        last_max_id_dict[id_group].set(new_id)
+      else:
+        last_max_id_value = last_max_id.value
+        if new_id <= last_max_id_value:
+          raise ValueError('The last id %s stored in ZODB dictionary is higher'
+                           ' than the new id %s generated for id_group %r.'
+                           ' Invoke %s/rebuildSqlTable to fix this problem.'
+                           % (last_max_id_value, new_id, id_group,
+                              self.absolute_url()))
+        # Check the store interval to store the data
+        if last_max_id_value <= new_id - (self.getStoreInterval() or 1):
+          last_max_id.set(new_id)
     return new_id
 
   def _updateSqlTable(self):
-- 
2.30.9