Limit size of cache to reset per notify call

issue8781
review309371003
This commit is contained in:
Cédric Krier
2020-04-19 16:37:51 +02:00
parent 8824c5a11b
commit cd97362e08
+7 -4
View File
@@ -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)