[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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user