diff --git a/docs/index.rst b/docs/index.rst index fdc6e50..769ae35 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -43,10 +43,11 @@ but has a database instance associate to it:: author = couchdb.StringProperty() content = couchdb.StringProperty() -The extension make use of two configuration variables, but only +The extension make use of three configuration variables, but only ``COUCHDB_DATABASE`` is required. The database will be created if it does -not already exists. The other configuration variable is ``COUCHDB_SERVER``, -which sets the server to connect to. +not already exists. Two other configuration variables are ``COUCHDB_SERVER``, +which sets the server to connect to, and ``COUCHDB_KEEPALIVE``, which sets +the least amount of connection that will be kept open. Defining Views -------------- diff --git a/flaskext/couchdbkit.py b/flaskext/couchdbkit.py index dcdfa94..ffe3f8e 100644 --- a/flaskext/couchdbkit.py +++ b/flaskext/couchdbkit.py @@ -13,6 +13,7 @@ import couchdbkit from flask import current_app from couchdbkit import Server +from restkit import SimplePool from couchdbkit.loaders import FileSystemDocsLoader @@ -40,9 +41,13 @@ class CouchDBKit(object): def __init__(self, app): app.config.setdefault('COUCHDB_SERVER', 'http://localhost:5984/') app.config.setdefault('COUCHDB_DATABASE', None) + app.config.setdefault('COUCHDB_KEEPALIVE', 2) + + pool = SimplePool(keepalive=app.config.get('COUCHDB_KEEPALIVE')) + server = Server(app.config.get('COUCHDB_SERVER'), pool_instance=pool) self.app = app - self.server = Server(app.config.get('COUCHDB_SERVER')) + self.server = server _include_couchdbkit(self) self.init_db()