1. Benoit Chesneau
  2. Pypaste

Commits

ben...@enlil  committed 51df040

you don't need to test if db is created each time you connect to it.
Doi it at startup....

  • Participants
  • Parent commits 36b8914
  • Branches default

Comments (0)

Files changed (2)

File friendpaste/application.py

View file
 from werkzeug.exceptions import HTTPException, BadRequest, Forbidden, \
      NotFound
 from jinja import Environment
-
-
+from couchdb import Server
 
 from friendpaste import settings
 from friendpaste.urls import map, all_views
         
         self.proxy = make_connection(settings.SERVER_URI, 
                 settings.DATABASE_NAME)
+        
+        # init views and create db
+        couchdb_server = Server(settings.SERVER_URI)
+        try:
+            db = couchdb_server.create(settings.DATABASE_NAME)
+        except:
+            db = couchdb_server[settings.DATABASE_NAME]
 
         try:
-            init_views(self.db) 
+            init_views(db) 
         except:
             pass
 

File friendpaste/dbsession.py

View file
 # limitations under the License.
 
 from couchdb import Server
+from werkzeug.routing import NotFound
 
 from friendpaste.utils import local_manager,ScopedRegistry
 
     def __init__(self, uri, dbname):
         self.uri = uri
         self.dbname = dbname
-        self._db = None
 
+    # TODO: better handling of conection lost 
     def _get_db(self):
-        # we could do more here like looking if 
-        # anything is wrong with the connection...
-        if self._db is None:
+        try:
             couchdb_server = Server(self.uri)
+        except:
+            # retry it please
             try:
-                self._db = couchdb_server.create(self.dbname)
+                couchdb_server = Server(self.uri)
             except:
-                self._db = couchdb_server[self.dbname]
-
-        return self._db
+                # ok say we don't find the page. 
+                raise NotFound
+        return couchdb_server[self.dbname]
     db = property(_get_db)
         
 class ScopedCouchDBSession(object):