Use tee to use iterators
authorThierry Florac <thierry.florac@onf.fr>
Mon, 02 Jul 2018 18:29:56 +0200
changeset 785 99772127f89b
parent 784 3ce9a6fabe43
child 786 fb45f422d0ce
Use tee to use iterators
src/pyams_content/shared/view/__init__.py
--- a/src/pyams_content/shared/view/__init__.py	Mon Jul 02 17:11:55 2018 +0200
+++ b/src/pyams_content/shared/view/__init__.py	Mon Jul 02 18:29:56 2018 +0200
@@ -18,6 +18,7 @@
 logger = logging.getLogger("PyAMS (content)")
 
 from datetime import datetime
+from itertools import tee
 
 # import interfaces
 from hypatia.interfaces import ICatalog
@@ -105,7 +106,8 @@
                                           reverse if reverse is not None else self.reversed_order,
                                           limit or self.limit)
             intids = get_utility(IIntIds)
-            views_cache.set_value(cache_key, [intids.queryId(item) for item in results])
+            cache, results = tee(results)
+            views_cache.set_value(cache_key, [intids.queryId(item) for item in cache])
             logger.debug("Storing view items to cache key {0}".format(cache_key))
         else:
             results = CatalogResultSet(results)