From 7c7be184863f4fe943df949c1fb586ba216e5ccc Mon Sep 17 00:00:00 2001 From: Ayush Tiwari <ayush.tiwari@nexedi.com> Date: Mon, 3 Oct 2016 14:46:56 +0000 Subject: [PATCH] sql_catalog: Simplify LazyIndexationParameterList to improve performance __getitem__ function for LazyIndexationParameterList eats up a lot of performance. This patch tries to simplify the code to improve performance. --- product/ZSQLCatalog/SQLCatalog.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py index af7558c139..e20c7b90b3 100644 --- a/product/ZSQLCatalog/SQLCatalog.py +++ b/product/ZSQLCatalog/SQLCatalog.py @@ -255,10 +255,9 @@ class LazyIndexationParameterList(tuple): document = self._document_list[index] attribute = self._attribute global_cache_key = (document.uid, attribute) - global_cache = self._global_cache - if global_cache_key in global_cache: - value = global_cache[global_cache_key] - else: + try: + value = self._global_cache[global_cache_key] + except KeyError: value = getattr(document, attribute, None) if callable(value): try: @@ -271,7 +270,7 @@ class LazyIndexationParameterList(tuple): error=True, ) value = None - global_cache[global_cache_key] = value + self._global_cache[global_cache_key] = value return value def __iter__(self): -- 2.30.9