[csw-devel] SF.net SVN: gar:[16964] csw/mgar/gar/v2/lib/web/pkgdb_web.py
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Wed Feb 1 14:03:20 CET 2012
Revision: 16964
http://gar.svn.sourceforge.net/gar/?rev=16964&view=rev
Author: wahwah
Date: 2012-02-01 13:03:19 +0000 (Wed, 01 Feb 2012)
Log Message:
-----------
pkgdb-web: Eliminate db reconnects.
This cuts some of the request latency, at the risk of permanently losing the
db connection.
Modified Paths:
--------------
csw/mgar/gar/v2/lib/web/pkgdb_web.py
Modified: csw/mgar/gar/v2/lib/web/pkgdb_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/pkgdb_web.py 2012-02-01 12:29:57 UTC (rev 16963)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py 2012-02-01 13:03:19 UTC (rev 16964)
@@ -13,6 +13,8 @@
import datetime
from sqlobject import sqlbuilder
+connected_to_db = False
+
urls_html = (
r'/', 'index',
r'/srv4/', 'Srv4List',
@@ -48,9 +50,17 @@
'lib/web/templates/')
def ConnectToDatabase():
- configuration.SetUpSqlobjectConnection()
+ """Connect to the database only if necessary.
+ One problem with this approach might be that if the connection is lost, the
+ script will never try to reconnect (unless it's done by the ORM).
+ """
+ global connected_to_db
+ if not connected_to_db:
+ configuration.SetUpSqlobjectConnection()
+ connected_to_db = True
+
class index(object):
def GET(self):
return render.index()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list