Commit 651e04e1 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Cache database configuration in memory

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2310 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent e6a3046b
...@@ -49,6 +49,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -49,6 +49,7 @@ class MySQLDatabaseManager(DatabaseManager):
super(MySQLDatabaseManager, self).__init__() super(MySQLDatabaseManager, self).__init__()
self.user, self.passwd, self.db = self._parse(database) self.user, self.passwd, self.db = self._parse(database)
self.conn = None self.conn = None
self._config = {}
self._connect() self._connect()
def getPartition(self, oid_or_tid): def getPartition(self, oid_or_tid):
...@@ -129,6 +130,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -129,6 +130,7 @@ class MySQLDatabaseManager(DatabaseManager):
return self.conn.escape_string(s) return self.conn.escape_string(s)
def setup(self, reset = 0): def setup(self, reset = 0):
self._config.clear()
q = self.query q = self.query
if reset: if reset:
...@@ -196,17 +198,22 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -196,17 +198,22 @@ class MySQLDatabaseManager(DatabaseManager):
) ENGINE = InnoDB""") ) ENGINE = InnoDB""")
def getConfiguration(self, key): def getConfiguration(self, key):
if key in self._config:
return self._config[key]
q = self.query q = self.query
e = self.escape e = self.escape
key = e(str(key)) sql_key = e(str(key))
try: try:
return q("SELECT value FROM config WHERE name = '%s'" % key)[0][0] r = q("SELECT value FROM config WHERE name = '%s'" % sql_key)[0][0]
except IndexError: except IndexError:
raise KeyError, key raise KeyError, key
self._config[key] = r
return r
def _setConfiguration(self, key, value): def _setConfiguration(self, key, value):
q = self.query q = self.query
e = self.escape e = self.escape
self._config[key] = value
key = e(str(key)) key = e(str(key))
if value is None: if value is None:
value = 'NULL' value = 'NULL'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment