44import queue
55import threading
66from collections import defaultdict
7+ from collections .abc import Generator
78from contextlib import contextmanager
8- from typing import Generator
99
1010from odoo .api import Environment
1111
@@ -45,8 +45,8 @@ class FastApiAppPool:
4545 updated by the increment of the `cache_sequence` SQL sequence. This cache sequence
4646 on the registry is reloaded from the DB on each request made to a specific database.
4747 When an app is retrieved from the pool, we always compare the cache sequence of
48- the pool with the cache sequence of the registry. If the two sequences are different,
49- we invalidate the pool and save the new cache sequence on the pool.
48+ the pool with the cache sequence of the registry. If the two sequences are
49+ different, we invalidate the pool and save the new cache sequence on the pool.
5050
5151 The cache is based on a defaultdict of defaultdict of queue.Queue. We are cautious
5252 that the use of defaultdict is not thread-safe for operations that modify the
@@ -61,9 +61,9 @@ class FastApiAppPool:
6161 """
6262
6363 def __init__ (self ):
64- self ._queue_by_db_by_root_path : dict [
65- str , dict [ str , queue .Queue [ FastAPI ]]
66- ] = defaultdict ( lambda : defaultdict ( queue . Queue ) )
64+ self ._queue_by_db_by_root_path : dict [str , dict [ str , queue . Queue [ FastAPI ]]] = (
65+ defaultdict ( lambda : defaultdict ( queue .Queue ))
66+ )
6767 self .__cache_sequences = {}
6868 self ._lock = threading .Lock ()
6969
@@ -108,13 +108,19 @@ def get_cache_sequence(self, key: str) -> int:
108108
109109 def set_cache_sequence (self , key : str , value : int ) -> None :
110110 with self ._lock :
111- if key not in self .__cache_sequences or value != self .__cache_sequences [key ]:
111+ if (
112+ key not in self .__cache_sequences
113+ or value != self .__cache_sequences [key ]
114+ ):
112115 self .__cache_sequences [key ] = value
113116
114117 def _check_cache (self , env : Environment ) -> None :
115118 cache_sequences = env .registry .cache_sequences
116119 for key , value in cache_sequences .items ():
117- if value != self .get_cache_sequence (key ) and self .get_cache_sequence (key ) != 0 :
120+ if (
121+ value != self .get_cache_sequence (key )
122+ and self .get_cache_sequence (key ) != 0
123+ ):
118124 _logger .info (
119125 "Cache registry updated, reset fastapi_app pool for the current "
120126 "database"
0 commit comments