[FIX] registry: avoid discarding registry or cache when the registry is fresh
authorOlivier Dony <odo@openerp.com>
Fri, 11 Oct 2013 10:03:13 +0000 (12:03 +0200)
committerOlivier Dony <odo@openerp.com>
Fri, 11 Oct 2013 10:03:13 +0000 (12:03 +0200)
When the sequence value is 1 it means that either:
 - the registry was just instantiated, so there is no
   reason to reload it immediately, the real checks will
   start at next request
 - the db was just created with new sequences set to 1,
   so there has been no change to reload

In both cases there is no good reason to reload the
registry, and it is actually a performance killer,
especially for cron workers that keep iterating on
the list of databases.

bzr revid: odo@openerp.com-20131011100313-4bud8e9xq2afp9z7

openerp/modules/registry.py

index 14b5dd9..8c68663 100644 (file)
@@ -284,16 +284,14 @@ class RegistryManager(object):
                 r, c = cr.fetchone()
                 # Check if the model registry must be reloaded (e.g. after the
                 # database has been updated by another process).
-                if registry.base_registry_signaling_sequence != r:
+                if registry.base_registry_signaling_sequence > 1 and registry.base_registry_signaling_sequence != r:
                     _logger.info("Reloading the model registry after database signaling.")
                     registry = cls.new(db_name)
-                    registry.base_registry_signaling_sequence = r
                 # Check if the model caches must be invalidated (e.g. after a write
                 # occured on another process). Don't clear right after a registry
                 # has been reload.
-                elif registry.base_cache_signaling_sequence != c:
+                if registry.base_cache_signaling_sequence > 1 and registry.base_cache_signaling_sequence != c:
                     _logger.info("Invalidating all model caches after database signaling.")
-                    registry.base_cache_signaling_sequence = c
                     registry.clear_caches()
                     registry.reset_any_cache_cleared()
                     # One possible reason caches have been invalidated is the
@@ -303,6 +301,8 @@ class RegistryManager(object):
                         for column in model._columns.values():
                             if hasattr(column, 'digits_change'):
                                 column.digits_change(cr)
+                registry.base_registry_signaling_sequence = r
+                registry.base_cache_signaling_sequence = c
             finally:
                 cr.close()