From cd97362e08d517c8e022bfb38f9f43d03150aafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 19 Apr 2020 16:37:51 +0200 Subject: [PATCH] Limit size of cache to reset per notify call issue8781 review309371003 --- trytond/cache.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/trytond/cache.py b/trytond/cache.py index 9dbb089434..b80e555575 100644 --- a/trytond/cache.py +++ b/trytond/cache.py @@ -16,7 +16,7 @@ from sql.functions import CurrentTimestamp, Function from trytond import backend from trytond.config import config from trytond.transaction import Transaction -from trytond.tools import resolve +from trytond.tools import resolve, grouped_slice __all__ = ['BaseCache', 'Cache', 'LRUDict'] _clear_timeout = config.getint('cache', 'clean_timeout', default=5 * 60) @@ -213,9 +213,12 @@ class MemoryCache(BaseCache): dbname = database.name if not _clear_timeout and transaction.database.has_channel(): with transaction.connection.cursor() as cursor: - cursor.execute( - 'NOTIFY "%s", %%s' % cls._channel, - (json.dumps(list(reset), separators=(',', ':')),)) + # The count computed as + # 8000 (max notify size) / 64 (max name data len) + for sub_reset in grouped_slice(reset, 125): + cursor.execute( + 'NOTIFY "%s", %%s' % cls._channel, + (json.dumps(list(sub_reset), separators=(',', ':')),)) else: connection = database.get_connection( readonly=False, autocommit=True)