Author: luke
Date: 2007-02-26 10:30:42 -0700 (Mon, 26 Feb 2007)
New Revision: 2352
Modified:
SQLObject/branches/sqlbuilder-views/sqlobject/converters.py
SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py
SQLObject/branches/sqlbuilder-views/sqlobject/views.py
Log:
cleaner sqlrepr/tablesUsed caching, stable view column list for unions
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/converters.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/converters.py 2007-02-23 19:11:57 UTC (rev 2351)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/converters.py 2007-02-26 17:30:42 UTC (rev 2352)
@@ -237,17 +237,20 @@
(type(obj), repr(obj))
return converter(obj, db)
else:
-# return reprFunc(db)
- cache = getattr(obj, '_sqlreprCache', {})
- if not isinstance(cache, dict):
- #Alias etc
- cache = {}
- ret = cache.get(db, None)
+ doCache = hasattr(db, 'doSQLReprCache')
+ ret = None
+ if doCache:
+ cache = getattr(obj, '_sqlreprCache', {})
+ if not isinstance(cache, dict):
+ #Alias etc
+ cache = {}
+ ret = cache.get(db, None)
if ret is None:
ret = reprFunc(db)
- try:
- cache[db] = ret
- obj._sqlreprCache = cache
- except TypeError:
- pass
+ if doCache:
+ try:
+ cache[db] = ret
+ obj._sqlreprCache = cache
+ except TypeError:
+ pass
return ret
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py 2007-02-23 19:11:57 UTC (rev 2351)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py 2007-02-26 17:30:42 UTC (rev 2352)
@@ -188,7 +188,14 @@
def tablesUsed(self, db):
return self.tablesUsedDict(db).keys()
def tablesUsedDict(self, db):
- tables = getattr(db, 'tableCache', {}).get(id(self), None)
+ doCache = hasattr(db, 'doTablesUsedCache')
+ tables = None
+ if doCache:
+ cache = getattr(self, '_tablesUsedCache', {})
+ if not isinstance(cache, dict):
+ #Alias etc
+ cache = {}
+ tables = cache.get(db, None)
if tables is None:
tables = {}
for table in self.tablesUsedImmediate():
@@ -197,7 +204,12 @@
tables[table] = 1
for component in self.components():
tables.update(tablesUsedDict(component, db))
- getattr(db, 'tableCache', {})[id(self)] = tables
+ if doCache:
+ try:
+ cache[db] = tables
+ self._tablesUsedCache = cache
+ except TypeError:
+ pass
return tables
def tablesUsedImmediate(self):
return []
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/views.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/views.py 2007-02-23 19:11:57 UTC (rev 2351)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/views.py 2007-02-26 17:30:42 UTC (rev 2352)
@@ -88,7 +88,9 @@
columns = [ColumnAS(cls.sqlmeta.idName, 'id')]
# {sqlrepr-key: [restriction, *aggregate-column]}
aggregates = {'':[None]}
- for n,col in cls.sqlmeta.columns.iteritems():
+ inverseColumns = dict([(y,x) for x,y in cls.sqlmeta.columns.iteritems()])
+ for col in cls.sqlmeta.columnList:
+ n = inverseColumns[col]
ascol = ColumnAS(col.dbName, n)
if isAggregate(col.dbName):
restriction = getattr(col, 'aggregateClause',None)
@@ -109,8 +111,9 @@
clause=clause)
aggregates = aggregates.values()
+ #print cls.__name__, sqlrepr(aggregates, dbName)
- if len(aggregates) > 1:
+ if aggregates != [[None]]:
join = []
last_alias = "%s_base" % alias
last_id = "id"
|