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

Side by Side Diff: chrome/common/extensions/docs/server2/chained_compiled_file_system.py

Issue 429723005: Docserver: Only fetch content versions in the crons, not their contents. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no getfileversion 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 unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from compiled_file_system import CompiledFileSystem 5 from compiled_file_system import CompiledFileSystem
6 from docs_server_utils import StringIdentity 6 from docs_server_utils import StringIdentity
7 from file_system import FileNotFoundError 7 from file_system import FileNotFoundError
8 from future import Future 8 from future import Future
9 from path_util import ToDirectory 9 from path_util import ToDirectory
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 '''|compiled_fs_chain| is a list of tuples (compiled_fs, file_system). 43 '''|compiled_fs_chain| is a list of tuples (compiled_fs, file_system).
44 ''' 44 '''
45 assert len(compiled_fs_chain) > 0 45 assert len(compiled_fs_chain) > 0
46 self._compiled_fs_chain = compiled_fs_chain 46 self._compiled_fs_chain = compiled_fs_chain
47 self._identity = identity 47 self._identity = identity
48 48
49 def GetFromFile(self, path): 49 def GetFromFile(self, path):
50 return self._GetImpl( 50 return self._GetImpl(
51 path, 51 path,
52 lambda compiled_fs: compiled_fs.GetFromFile(path), 52 lambda compiled_fs: compiled_fs.GetFromFile(path),
53 lambda compiled_fs: compiled_fs.GetFileVersion(path)) 53 lambda compiled_fs: compiled_fs._GetFileVersionFromCache(path))
54 54
55 def GetFromFileListing(self, path): 55 def GetFromFileListing(self, path):
56 path = ToDirectory(path) 56 path = ToDirectory(path)
57 return self._GetImpl( 57 return self._GetImpl(
58 path, 58 path,
59 lambda compiled_fs: compiled_fs.GetFromFileListing(path), 59 lambda compiled_fs: compiled_fs.GetFromFileListing(path),
60 lambda compiled_fs: compiled_fs.GetFileListingVersion(path)) 60 lambda compiled_fs: compiled_fs._GetFileListingVersionFromCache(path))
61 61
62 def _GetImpl(self, path, reader, version_getter): 62 def _GetImpl(self, path, reader, version_getter):
63 # Strategy: Get the current version of |path| in main FileSystem, then run 63 # Strategy: Get the current version of |path| in main FileSystem, then run
64 # through |_compiled_fs_chain| in *reverse* to find the "oldest" FileSystem 64 # through |_compiled_fs_chain| in *reverse* to find the "oldest" FileSystem
65 # with an up-to-date version of that file. 65 # with an up-to-date version of that file.
66 # 66 #
67 # Obviously, if files have been added in the main FileSystem then none of 67 # Obviously, if files have been added in the main FileSystem then none of
68 # the older FileSystems will be able to find it. 68 # the older FileSystems will be able to find it.
69 read_futures = [(reader(compiled_fs), compiled_fs) 69 read_and_version_futures = [(reader(fs), version_getter(fs), fs)
70 for compiled_fs in self._compiled_fs_chain] 70 for fs in self._compiled_fs_chain]
71 71
72 def resolve(): 72 def resolve():
73 try: 73 try:
74 first_compiled_fs = self._compiled_fs_chain[0]
75 # The first file system contains both files of a newer version and 74 # The first file system contains both files of a newer version and
76 # files shared with other compiled file systems. We are going to try 75 # files shared with other compiled file systems. We are going to try
77 # each compiled file system in the reverse order and return the data 76 # each compiled file system in the reverse order and return the data
78 # when version matches. Data cached in other compiled file system will 77 # when version matches. Data cached in other compiled file system will
79 # be reused whenever possible so that we don't need to recompile things 78 # be reused whenever possible so that we don't need to recompile things
80 # that are not changed across these file systems. 79 # that are not changed across these file systems.
81 first_version = version_getter(first_compiled_fs) 80 first_version = read_and_version_futures[0][1].Get()
82 for read_future, compiled_fs in reversed(read_futures): 81 for (read_future,
83 if version_getter(compiled_fs) == first_version: 82 version_future,
83 compiled_fs) in reversed(read_and_version_futures):
84 if version_future.Get() == first_version:
84 return read_future.Get() 85 return read_future.Get()
85 except FileNotFoundError: 86 except FileNotFoundError:
86 pass 87 pass
87 # Try an arbitrary operation again to generate a realistic stack trace. 88 # Try an arbitrary operation again to generate a realistic stack trace.
88 return read_futures[0][0].Get() 89 return read_and_version_futures[0][0].Get()
89 90
90 return Future(callback=resolve) 91 return Future(callback=resolve)
91 92
92 def GetIdentity(self): 93 def GetIdentity(self):
93 return self._identity 94 return self._identity
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698