Source

orange-bioinformatics / _bioinformatics / obiKEGG / databases.py

Diff from to

_bioinformatics/obiKEGG/databases.py

 from __future__ import absolute_import
 
 import re
+from contextlib import closing
 
 from . import entry
 from .entry import fields
         if keys is None:
             keys = self.keys()
 
-        keys = list(keys)
+        keys = map(self._add_db, keys)
+
+        get = self.api.get
+
+        # drop all keys with a valid cache entry to minimize the number
+        # of 'get' requests.
+        with closing(get.cache_store()) as store:
+            def is_uncached(key):
+                return not get.key_has_valid_cache(get.key_from_args((key,)),
+                                                   store)
+            keys = filter(is_uncached, keys)
+
         start = 0
+
         while start < len(keys):
             batch = keys[start: start + batch_size]
-            batch = map(self._add_db, batch)
-
             self.api.get(batch)
 
             if progress_callback:
         """
         entries = []
         batch_size = 10
-        keys = list(keys)
+        keys = map(self._add_db, keys)
+
+        # Precache the entries first
+        self.pre_cache(keys)
+
         start = 0
         while start < len(keys):
             batch = keys[start: start + batch_size]
-            batch = map(self._add_db, batch)
             batch_entries = self.api.get(batch)
             if batch_entries is not None:
                 batch_entries = batch_entries.split("///\n")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.