cache table reflection (it was *very* slow)

This commit is contained in:
Seb Bacon 2011-04-10 09:44:44 +01:00
parent 11d3777a66
commit 5cb20d1d45
1 changed files with 8 additions and 3 deletions

View File

@ -7,6 +7,8 @@ from ckan.authz import Authorizer
from ckan.model.authz import PSEUDO_USER__VISITOR
from ckan.lib.base import *
cached_tables = {}
def init_tables():
metadata = MetaData()
@ -24,9 +26,12 @@ def init_tables():
def get_table(name):
meta = MetaData()
meta.reflect(bind=model.meta.engine)
return meta.tables[name]
if name not in cached_tables:
meta = MetaData()
meta.reflect(bind=model.meta.engine)
table = meta.tables[name]
cached_tables[name] = table
return cached_tables[name]
def _update_visits(table_name, item_id, recently, ever):