]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
reimplement PrepareManager.maintain() calling other public methods
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 16 Nov 2021 14:13:49 +0000 (15:13 +0100)
committerDenis Laxalde <denis.laxalde@dalibo.com>
Mon, 29 Nov 2021 08:50:50 +0000 (09:50 +0100)
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

index e8fbeb9ff80aba8af83a94ebeafb18e3882235b8..4ebca8d4a1772bc512cedc3bb6a9b6054c5438b6 100644 (file)
@@ -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: