Merge pull request #846 from niphlod/enhancement/repr_cache
caches recursive selects for references
This commit is contained in:
+39
-8
@@ -2627,6 +2627,7 @@ class SQLFORM(FORM):
|
|||||||
htmltable = TABLE(COLGROUP(*cols), THEAD(head))
|
htmltable = TABLE(COLGROUP(*cols), THEAD(head))
|
||||||
tbody = TBODY()
|
tbody = TBODY()
|
||||||
numrec = 0
|
numrec = 0
|
||||||
|
repr_cache = {}
|
||||||
for row in rows:
|
for row in rows:
|
||||||
trcols = []
|
trcols = []
|
||||||
id = row[field_id]
|
id = row[field_id]
|
||||||
@@ -2642,14 +2643,31 @@ class SQLFORM(FORM):
|
|||||||
value = row[str(field)]
|
value = row[str(field)]
|
||||||
maxlength = maxtextlengths.get(str(field), maxtextlength)
|
maxlength = maxtextlengths.get(str(field), maxtextlength)
|
||||||
if field.represent:
|
if field.represent:
|
||||||
try:
|
if field.type.startswith('reference'):
|
||||||
value = field.represent(value, row)
|
if field not in repr_cache:
|
||||||
except KeyError:
|
repr_cache[field] = {}
|
||||||
try:
|
try:
|
||||||
value = field.represent(
|
nvalue = repr_cache[field][value]
|
||||||
value, row[field.tablename])
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
try:
|
||||||
|
nvalue = field.represent(value, row)
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
nvalue = field.represent(
|
||||||
|
value, row[field.tablename])
|
||||||
|
except KeyError:
|
||||||
|
nvalue = None
|
||||||
|
repr_cache[field][value] = nvalue
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
nvalue = field.represent(value, row)
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
nvalue = field.represent(
|
||||||
|
value, row[field.tablename])
|
||||||
|
except KeyError:
|
||||||
|
nvalue = None
|
||||||
|
value = nvalue
|
||||||
elif field.type == 'boolean':
|
elif field.type == 'boolean':
|
||||||
value = INPUT(_type="checkbox", _checked=value,
|
value = INPUT(_type="checkbox", _checked=value,
|
||||||
_disabled=True)
|
_disabled=True)
|
||||||
@@ -3119,6 +3137,7 @@ class SQLTABLE(TABLE):
|
|||||||
components.append(THEAD(TR(*row)))
|
components.append(THEAD(TR(*row)))
|
||||||
|
|
||||||
tbody = []
|
tbody = []
|
||||||
|
repr_cache = {}
|
||||||
for (rc, record) in enumerate(sqlrows):
|
for (rc, record) in enumerate(sqlrows):
|
||||||
row = []
|
row = []
|
||||||
if rc % 2 == 1:
|
if rc % 2 == 1:
|
||||||
@@ -3177,7 +3196,11 @@ class SQLTABLE(TABLE):
|
|||||||
href = '%s/%s?%s' % (linkto, tref, urllib.urlencode({fref: r}))
|
href = '%s/%s?%s' % (linkto, tref, urllib.urlencode({fref: r}))
|
||||||
r = A(represent(field, r, record), _href=str(href))
|
r = A(represent(field, r, record), _href=str(href))
|
||||||
elif field.represent:
|
elif field.represent:
|
||||||
r = represent(field, r, record)
|
if field not in repr_cache:
|
||||||
|
repr_cache[field] = {}
|
||||||
|
if r not in repr_cache[field]:
|
||||||
|
repr_cache[field][r] = represent(field, r, record)
|
||||||
|
r = repr_cache[field][r]
|
||||||
elif linkto and hasattr(field._table, '_primarykey')\
|
elif linkto and hasattr(field._table, '_primarykey')\
|
||||||
and fieldname in field._table._primarykey:
|
and fieldname in field._table._primarykey:
|
||||||
# have to test this with multi-key tables
|
# have to test this with multi-key tables
|
||||||
@@ -3294,6 +3317,7 @@ class ExportClass(object):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
represented = []
|
represented = []
|
||||||
|
repr_cache = {}
|
||||||
for record in self.rows:
|
for record in self.rows:
|
||||||
row = []
|
row = []
|
||||||
for col in self.rows.colnames:
|
for col in self.rows.colnames:
|
||||||
@@ -3309,7 +3333,14 @@ class ExportClass(object):
|
|||||||
if field.type == 'blob' and value is not None:
|
if field.type == 'blob' and value is not None:
|
||||||
value = ''
|
value = ''
|
||||||
elif field.represent:
|
elif field.represent:
|
||||||
value = field.represent(value, record)
|
if field.type.startswith('reference'):
|
||||||
|
if field not in repr_cache:
|
||||||
|
repr_cache[field] = {}
|
||||||
|
if value not in repr_cache[field]:
|
||||||
|
repr_cache[field][value] = field.represent(value, record)
|
||||||
|
value = repr_cache[field][value]
|
||||||
|
else:
|
||||||
|
value = field.represent(value, record)
|
||||||
row.append(none_exception(value))
|
row.append(none_exception(value))
|
||||||
|
|
||||||
represented.append(row)
|
represented.append(row)
|
||||||
|
|||||||
Reference in New Issue
Block a user