[snapshot/master] No longer use DBUtils
---
web/app/snapshot/controllers/archive.py | 1 +
web/app/snapshot/controllers/root.py | 2 +-
web/app/snapshot/lib/app_globals.py | 4 ++--
web/app/snapshot/lib/dbinstance.py | 6 ++++--
4 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/web/app/snapshot/controllers/archive.py b/web/app/snapshot/controllers/archive.py
index c54df2b..8d20620 100644
--- a/web/app/snapshot/controllers/archive.py
+++ b/web/app/snapshot/controllers/archive.py
@@ -56,6 +56,7 @@ class ArchiveController(BaseController):
def _db_close(self):
if not self.db is None:
self.db.close()
+ self.db = None
def root(self):
diff --git a/web/app/snapshot/controllers/root.py b/web/app/snapshot/controllers/root.py
index b2b3165..460e17c 100644
--- a/web/app/snapshot/controllers/root.py
+++ b/web/app/snapshot/controllers/root.py
@@ -12,8 +12,8 @@ log = logging.getLogger(__name__)
class RootController(BaseController):
def index(self):
+ db = DBInstance(g.pool)
try:
- db = DBInstance(g.pool)
c.names = link_quote_array(g.shm.archives_get_list(db))
c.srcstarts = link_quote_array(g.shm.packages_get_name_starts(db))
set_expires(int(config['app_conf']['expires.root']))
diff --git a/web/app/snapshot/lib/app_globals.py b/web/app/snapshot/lib/app_globals.py
index 7375af2..793cbd3 100644
--- a/web/app/snapshot/lib/app_globals.py
+++ b/web/app/snapshot/lib/app_globals.py
@@ -1,7 +1,7 @@
"""The application's Globals object"""
from pylons import config
import psycopg2
-from DBUtils.PooledDB import PooledDB
+import psycopg2.pool
from snapshot.model.snapshotmodel import SnapshotModel
import yaml
@@ -25,7 +25,7 @@ class Globals(object):
newkey = key.replace("snapshot.db.", '', 1)
db_config[newkey] = app_conf[key]
- self.pool = PooledDB(psycopg2, 5, **db_config)
+ self.pool = psycopg2.pool.ThreadedConnectionPool(5, 20, **db_config)
self.shm = SnapshotModel(app_conf['snapshot.farmpath'], self.pool)
default_expires = {}
diff --git a/web/app/snapshot/lib/dbinstance.py b/web/app/snapshot/lib/dbinstance.py
index 747c342..a1d845d 100644
--- a/web/app/snapshot/lib/dbinstance.py
+++ b/web/app/snapshot/lib/dbinstance.py
@@ -2,7 +2,8 @@ import psycopg2.extras
class DBInstance:
def __init__(self, pool):
- self.conn = pool.connection()
+ self.pool = pool
+ self.conn = pool.getconn()
def execute(self, *args, **kw):
c = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
@@ -16,7 +17,8 @@ class DBInstance:
return rows
def close(self):
- self.conn.close()
+ self.execute('ROLLBACK').close()
+ self.pool.putconn(self.conn)
def query_one(self, *args, **kw):
all = self.query(*args, **kw)
--
1.5.6.5
Reply to: