From: Daniele Varrazzo Date: Tue, 16 Nov 2021 14:13:49 +0000 (+0100) Subject: reimplement PrepareManager.maintain() calling other public methods X-Git-Tag: pool-3.1~98^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f25b29c49d5bfdcd2ee732c86264eae2b03d22b1;p=thirdparty%2Fpsycopg.git 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. --- diff --git a/psycopg/psycopg/_preparing.py b/psycopg/psycopg/_preparing.py index e8fbeb9ff..4ebca8d4a 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: