[PATCH 3 of 9 cubicweb] [server] extract creating a new cnxset in a _new_cnxset() helper

Philippe Pepiot ph at itsalwaysdns.eu
Tue Mar 31 18:28:58 CEST 2020


# HG changeset patch
# User Philippe Pepiot <ph at itsalwaysdns.eu>
# Date 1585574636 -7200
#      Mon Mar 30 15:23:56 2020 +0200
# Node ID 0dca6687fcf5fd2754da447856360c365d8d15c2
# Parent  ef81cde04bf23382c0eee054a75ca815cb308aa6
# Available At https://philpep.org/pub/hg/cubicweb
#              hg pull https://philpep.org/pub/hg/cubicweb -r 0dca6687fcf5
[server] extract creating a new cnxset in a _new_cnxset() helper

So we can move logic specific to _CnxSetPool here.

diff --git a/cubicweb/server/repository.py b/cubicweb/server/repository.py
--- a/cubicweb/server/repository.py
+++ b/cubicweb/server/repository.py
@@ -152,6 +152,9 @@ class _BaseCnxSet:
         return None
 
     def get(self):
+        return self._new_cnxset()
+
+    def _new_cnxset(self):
         return self._source.wrapped_connection()
 
     def release(self, cnxset):
@@ -173,9 +176,12 @@ class _CnxSetPool(_BaseCnxSet):
         self._queue = queue.Queue()
 
         for i in range(size):
-            cnxset = source.wrapped_connection()
-            self._cnxsets.append(cnxset)
-            self._queue.put_nowait(cnxset)
+            self._queue.put_nowait(self._new_cnxset())
+
+    def _new_cnxset(self):
+        cnxset = super()._new_cnxset()
+        self._cnxsets.append(cnxset)
+        return cnxset
 
     def qsize(self):
         return self._queue.qsize()



More information about the cubicweb-devel mailing list