psycopg.git / summary / log / commit / refs

commit    f25b29c49d5bfdcd2ee732c86264eae2b03d22b1
Author:   Daniele Varrazzo <daniele.varrazzo@gmail.com>
Commit:   Denis Laxalde <denis.laxalde@dalibo.com>
Date:     Tue Nov 16 14:13:49 2021 +0000

    reimplement PrepareManager.maintain() calling other public methods
    
    This makes clearer that, in pipeline mode, we call them in two different
    moments, whereas in non-pipeline we call them in a single place.


psycopg/psycopg/_preparing.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/psycopg/psycopg/_preparing.py b/psycopg/psycopg/_preparing.py index e8fbeb9f..4ebca8d4 100644 --- a/psycopg/psycopg/_preparing.py +++ b/psycopg/psycopg/_preparing.py @@ -151,6 +151,7 @@ class PrepareManager: Note: This method is only called in pipeline mode. """ + # don't do anything if prepared statements are disabled if self.prepare_threshold is None: return None cached = self._check_in_cache_or_increment(query, prep, name) @@ -189,27 +190,11 @@ class PrepareManager: name: bytes, ) -> Optional[bytes]: """Maintain the cache of the prepared statements.""" - # don't do anything if prepared statements are disabled - if self.prepare_threshold is None: - return None - - cmd = self._should_discard(prep, results) - if cmd: - return cmd - - cached = self._check_in_cache_or_increment(query, prep, name) - if cached is None: - return None - - # The query is not in cache. Let's see if we must add it - if not self._check_results(results): + key = self.maybe_add_to_cache(query, prep, name) + if key is None: return None - # Ok, we got to the conclusion that this query is genuinely to prepare - key, value = cached - self._prepared[key] = value - - return self._rotate() + return self.validate(key, prep, name, results) def clear(self) -> Optional[bytes]: if self._prepared_idx: [parent: 4f8f331b96c8]