diff options
| author | Xavier Morel <xmo@odoo.com> | 2020-04-06 09:39:47 +0000 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2020-04-06 09:45:29 +0000 |
| commit | 9d37cecfca8e6b8d4c0e2880f422673c526a3aef (patch) | |
| tree | f1da785820ca7b0f3ab5124aff9212dac7267320 /odoo | |
| parent | eacc9bfe2579bf833a4620e4d1030fa075e18d32 (diff) | |
[FIX] core: iterations on LRU
Iteration methods on LRU were removed because they were not
thread-safe and it's not clear that making them thread-safe is the
correct thing to do, so not providing them seems saner.
I thought I'd looked for usages of the LRU but apparently didn't look
hard enough as I missed that it's used by the cron workers (apparently
using the threaded server we only run crons for dbs currently living
in the registry cache, the more you know).
Convert these to iterating on the LRU's internal mapping, and also
don't iterate on the LRU to clear its entries one by one when we can
just clear the entire thing safely, although Registry.delete_all
really seems completely unused.
closes odoo/odoo#49023
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Diffstat (limited to 'odoo')
| -rw-r--r-- | odoo/modules/registry.py | 5 | ||||
| -rw-r--r-- | odoo/service/server.py | 2 | ||||
| -rw-r--r-- | odoo/tools/cache.py | 2 |
3 files changed, 4 insertions, 5 deletions
diff --git a/odoo/modules/registry.py b/odoo/modules/registry.py index 02d1cd6e94a..9294cbbefdf 100644 --- a/odoo/modules/registry.py +++ b/odoo/modules/registry.py @@ -151,14 +151,13 @@ class Registry(Mapping): """ Delete the registry linked to a given database. """ with cls._lock: if db_name in cls.registries: - cls.registries.pop(db_name) + del cls.registries[db_name] @classmethod def delete_all(cls): """ Delete all the registries. """ with cls._lock: - for db_name in list(cls.registries.keys()): - cls.delete(db_name) + cls.registries.clear() # # Mapping abstract methods implementation diff --git a/odoo/service/server.py b/odoo/service/server.py index cffb6cd4373..0d22862818d 100644 --- a/odoo/service/server.py +++ b/odoo/service/server.py @@ -403,7 +403,7 @@ class ThreadedServer(CommonServer): time.sleep(SLEEP_INTERVAL + number) # Steve Reich timing style registries = odoo.modules.registry.Registry.registries _logger.debug('cron%d polling for jobs', number) - for db_name, registry in registries.items(): + for db_name, registry in registries.d.items(): if registry.ready: thread = threading.currentThread() thread.start_time = time.time() diff --git a/odoo/tools/cache.py b/odoo/tools/cache.py index 2d50b51aa94..dce88781824 100644 --- a/odoo/tools/cache.py +++ b/odoo/tools/cache.py @@ -204,7 +204,7 @@ def log_ormcache_stats(sig=None, frame=None): me = threading.currentThread() me_dbname = getattr(me, 'dbname', 'n/a') - for dbname, reg in sorted(Registry.registries.items()): + for dbname, reg in sorted(Registry.registries.d.items()): # set logger prefix to dbname me.dbname = dbname entries = defaultdict(int) |
