diff --git a/etc/trytond.conf b/etc/trytond.conf index 28f280384d..cbaaf75d17 100644 --- a/etc/trytond.conf +++ b/etc/trytond.conf @@ -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 diff --git a/trytond/config.py b/trytond/config.py index 77157001ea..3422ada61b 100644 --- a/trytond/config.py +++ b/trytond/config.py @@ -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) diff --git a/trytond/ir/__init__.py b/trytond/ir/__init__.py index 3fda6798ff..f3c16c2914 100644 --- a/trytond/ir/__init__.py +++ b/trytond/ir/__init__.py @@ -12,3 +12,4 @@ from export import * from rule import * import module from default import * +from cache import * diff --git a/trytond/ir/cache.py b/trytond/ir/cache.py new file mode 100644 index 0000000000..b7c758ccfb --- /dev/null +++ b/trytond/ir/cache.py @@ -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() diff --git a/trytond/tools/misc.py b/trytond/tools/misc.py index d0b89f19b2..dbd9ba1c76 100644 --- a/trytond/tools/misc.py +++ b/trytond/tools/misc.py @@ -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()