Neater database setup at application startup time; only .connect() it once, not once per schema file; don't build the db_pool twice

This commit is contained in:
Paul "LeoNerd" Evans 2014-08-20 16:40:51 +01:00
parent a8774cf351
commit 648796ef1d
1 changed files with 19 additions and 17 deletions

View File

@ -43,6 +43,17 @@ import re
logger = logging.getLogger(__name__)
SCHEMAS = [
"transactions",
"pdu",
"users",
"profiles",
"presence",
"im",
"room_aliases",
]
class SynapseHomeServer(HomeServer):
def build_http_client(self):
@ -65,24 +76,11 @@ class SynapseHomeServer(HomeServer):
don't have to worry about overwriting existing content.
"""
logging.info("Preparing database: %s...", self.db_name)
pool = adbapi.ConnectionPool(
'sqlite3', self.db_name, check_same_thread=False,
cp_min=1, cp_max=1)
schemas = [
"transactions",
"pdu",
"users",
"profiles",
"presence",
"im",
"room_aliases",
]
with sqlite3.connect(self.db_name) as db_conn:
for sql_loc in SCHEMAS:
sql_script = read_schema(sql_loc)
for sql_loc in schemas:
sql_script = read_schema(sql_loc)
with sqlite3.connect(self.db_name) as db_conn:
c = db_conn.cursor()
c.executescript(sql_script)
c.close()
@ -90,6 +88,10 @@ class SynapseHomeServer(HomeServer):
logging.info("Database prepared in %s.", self.db_name)
pool = adbapi.ConnectionPool(
'sqlite3', self.db_name, check_same_thread=False,
cp_min=1, cp_max=1)
return pool
def create_resource_tree(self, web_client, redirect_root_to_web_client):
@ -282,7 +284,7 @@ def setup():
redirect_root_to_web_client=True)
hs.start_listening(args.port)
hs.build_db_pool()
hs.get_db_pool()
if args.manhole:
f = twisted.manhole.telnet.ShellFactory()