Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1922)

Unified Diff: chrome/common/extensions/docs/server2/caching_file_system.py

Issue 512453002: Docserver: Add more skip_not_found support and cache "not found"s (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/caching_file_system.py
diff --git a/chrome/common/extensions/docs/server2/caching_file_system.py b/chrome/common/extensions/docs/server2/caching_file_system.py
index ecadb68ab5d4ee6938ff51e64da4e69c4ef1e37c..0bca4e815e699541887125062c97d9effa7f5173 100644
--- a/chrome/common/extensions/docs/server2/caching_file_system.py
+++ b/chrome/common/extensions/docs/server2/caching_file_system.py
@@ -57,7 +57,7 @@ class CachingFileSystem(FileSystem):
dir_stat = self._stat_object_store.Get(dir_path).Get()
if dir_stat is not None:
- return Future(value=make_stat_info(dir_stat))
+ return Future(callback=lambda: make_stat_info(dir_stat))
def next(dir_stat):
assert dir_stat is not None # should have raised a FileNotFoundError
@@ -107,7 +107,12 @@ class CachingFileSystem(FileSystem):
# the result returned to callers.
fresh_data = dict(
not at google - send to devlin 2014/08/26 20:59:34 This "fresh" thing is tripping me up. Maybe it sho
(path, data) for path, (data, version) in cached_read_values.iteritems()
- if stat_futures[path].Get().version == version)
+ if version and stat_futures[path].Get().version == version)
not at google - send to devlin 2014/08/26 20:59:34 I'm paranoid about version being 0 here. Could you
+
+ if skip_not_found:
+ # Remove paths for files that don't exist so reads aren't attempted.
not at google - send to devlin 2014/08/26 20:59:34 Could you mention why this works? Namely that this
+ paths = [path for path in paths
+ if cached_read_values.get(path, (None, True))[1]]
not at google - send to devlin 2014/08/26 20:59:34 Could you use 'path in cached_read_values'? This .
ahernandez 2014/08/27 00:07:22 The reason I have the ugly .get() call is because
not at google - send to devlin 2014/08/27 01:23:55 Ah I see. So to be clear: If the item isn't cached
if len(fresh_data) == len(paths):
# Everything was cached and up-to-date.
@@ -118,6 +123,11 @@ class CachingFileSystem(FileSystem):
self._read_object_store.SetMulti(
dict((path, (new_result, stat_futures[path].Get().version))
for path, new_result in new_results.iteritems()))
+ # Update the read cache to include files that weren't found, to prevent
+ # constantly trying to read a file we now know doesn't exist.
not at google - send to devlin 2014/08/26 20:59:34 Relating to comments above - I'm not sure we need
ahernandez 2014/08/27 00:07:22 I think the stat cache doesn't know about non-exis
not at google - send to devlin 2014/08/27 01:23:55 Ohh I see. Ok. What you have is fine. We should a
ahernandez 2014/08/27 17:33:28 I don't think we should be afraid of comments :)
+ self._read_object_store.SetMulti(
+ dict((path, (None, None)) for path in paths
+ if stat_futures[path].Get() is None))
new_results.update(fresh_data)
return new_results
# Read in the values that were uncached or old.

Powered by Google App Engine
This is Rietveld 408576698