Skip to content

Commit 0799d10

Browse files
Cache the friendly name lookup
1 parent 5e146be commit 0799d10

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/collective/collectionfilter/baseviews.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ def _exp_cachekey(method, self, target_collection, request):
297297
)
298298

299299

300+
def _field_title_cache_key(method, self, field_id):
301+
return (
302+
field_id[0],
303+
self.context.getTypeInfo().id
304+
)
305+
306+
300307
class BaseInfoView(BaseView):
301308

302309
# TODO: should just cache on request?
@@ -408,10 +415,13 @@ def get_fields_to_display(self):
408415
if hasattr(self.context, field)
409416
]
410417

418+
# Cache this function based on the index id and the dexterity type
419+
@ram.cache(_field_title_cache_key)
411420
def get_field_title(self, field):
412421
"""
413422
Field is a tuple, where the first index is the name of the field and the second the values for that field
414-
Returns the friendly version of the title
423+
Returns the friendly version of the title when possible, falling
424+
back to the ID if a firiendly name can't be found.
415425
"""
416426
index_id = field[0]
417427

@@ -420,7 +430,6 @@ def get_field_title(self, field):
420430
if field_id == index_id:
421431
return field_object.title
422432

423-
# Fallback to returning the ID if we can't find a friendly name for the field for the given index.
424433
return index_id
425434

426435
def get_field_values(self, field):

0 commit comments

Comments
 (0)