Replace table cache_clean with ir_cache object

Add configuration option for multi-server
This commit is contained in:
Cédric Krier
2008-08-10 18:51:12 +02:00
parent 8c10efa666
commit a7657cf223
5 changed files with 25 additions and 27 deletions
+3
View File
@@ -51,3 +51,6 @@ admin_passwd = admin
# Limit the number of thread.
max_thread = 40
# Allow to run more than one instance of trytond
#multi_server = False
+1
View File
@@ -33,6 +33,7 @@ class ConfigManager(object):
'smtp_password': False,
'data_path': '/var/lib/trytond',
'max_thread': 40,
'multi_server': False,
}
parser = optparse.OptionParser(version=VERSION)
+1
View File
@@ -12,3 +12,4 @@ from export import *
from rule import *
import module
from default import *
from cache import *
+12
View File
@@ -0,0 +1,12 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms.
from trytond.osv import OSV, fields
class Cache(OSV):
"Cache"
_name = 'ir.cache'
_description = __doc__
name = fields.Char('Name', required=True)
timestamp = fields.DateTime('Timestamp')
Cache()
+8 -27
View File
@@ -420,27 +420,12 @@ class Cache(object):
return cached_result
@staticmethod
def _create_db(cursor):
cursor.execute('SELECT tablename FROM pg_tables ' \
'WHERE tablename = \'cache_clean\'')
if not cursor.rowcount:
cursor.execute('CREATE TABLE cache_clean (' \
'"timestamp" timestamp without time zone, ' \
'"name" varchar NOT NULL, '
'PRIMARY key(name)'
')')
cursor.commit()
@staticmethod
def clean(dbname):
if not CONFIG['multi_server']:
return
cursor = pooler.get_db(dbname).cursor()
try:
cursor.execute('SELECT "timestamp", "name" FROM cache_clean')
except:
cursor.rollback()
Cache._create_db(cursor)
cursor.execute('SELECT "timestamp", "name" FROM cache_clean')
cursor.execute('SELECT "timestamp", "name" FROM ir_cache')
timestamps = {}
for timestamp, name in cursor.fetchall():
timestamps[name] = timestamp
@@ -457,20 +442,16 @@ class Cache(object):
@staticmethod
def reset(dbname, name):
if not CONFIG['multi_server']:
return
cursor = pooler.get_db(dbname).cursor()
try:
cursor.execute('SELECT name FROM cache_clean WHERE name = %s',
(name,))
except:
cursor.rollback()
Cache._create_db(cursor)
cursor.execute('SELECT name FROM cache_clean WHERE name = %s',
cursor.execute('SELECT name FROM ir_cache WHERE name = %s',
(name,))
if cursor.rowcount:
cursor.execute('UPDATE cache_clean SET "timestamp" = now() '\
cursor.execute('UPDATE ir_cache SET "timestamp" = now() '\
'WHERE name = %s', (name,))
else:
cursor.execute('INSERT INTO cache_clean ("timestamp", "name") ' \
cursor.execute('INSERT INTO ir_cache ("timestamp", "name") ' \
'VALUES (now(), %s)', (name,))
cursor.commit()
cursor.close()