changeset defde6b8f3de in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset&node=defde6b8f3de
description:
        Clear cache just after starting to listen

        When the thread is restarted, we do not know if we missed any payload. 
So we
        must clear the cache and the pool to have a clean start.

        issue11397
        review431631003
diffstat:

 trytond/cache.py |  10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diffs (27 lines):

diff -r f9f50619c89c -r defde6b8f3de trytond/cache.py
--- a/trytond/cache.py  Sun Sep 25 20:19:30 2022 +0200
+++ b/trytond/cache.py  Sun Sep 25 20:23:13 2022 +0200
@@ -210,6 +210,11 @@
             self._transaction_lower.get(dbname, self._default_lower))
 
     @classmethod
+    def _clear_all(cls, dbname):
+        for inst in cls._instances.values():
+            inst._clear(dbname)
+
+    @classmethod
     def sync(cls, transaction):
         database = transaction.database
         dbname = database.name
@@ -365,6 +370,11 @@
             cursor = conn.cursor()
             cursor.execute('LISTEN "%s"' % cls._channel)
             current_thread.listening = True
+
+            # Clear everything in case we missed a payload
+            Pool(dbname).refresh(_get_modules(cursor))
+            cls._clear_all(dbname)
+
             selector.register(conn, selectors.EVENT_READ)
             while cls._listener.get((pid, dbname)) == current_thread:
                 selector.select(timeout=60)

Reply via email to