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

Side by Side Diff: chrome/common/extensions/docs/server2/content_provider.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: rebase Created 6 years, 3 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 import logging 5 import logging
6 import mimetypes 6 import mimetypes
7 import posixpath 7 import posixpath
8 import traceback 8 import traceback
9 9
10 from compiled_file_system import SingleFile 10 from compiled_file_system import SingleFile
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 .Then(get_index_if_directory_exists)) 190 .Then(get_index_if_directory_exists))
191 191
192 # Try to find a file with the right name. If not, and it's a directory, 192 # Try to find a file with the right name. If not, and it's a directory,
193 # look for an index file in that directory. If nothing at all is found, 193 # look for an index file in that directory. If nothing at all is found,
194 # return the original |path| - its nonexistence will be caught up the stack. 194 # return the original |path| - its nonexistence will be caught up the stack.
195 return (find_file_with_name(path) 195 return (find_file_with_name(path)
196 .Then(lambda found: found or find_index_file()) 196 .Then(lambda found: found or find_index_file())
197 .Then(lambda found: found or path)) 197 .Then(lambda found: found or path))
198 198
199 def Cron(self): 199 def Cron(self):
200 futures = [self._path_canonicalizer.Cron()] 200 def map_cron_paths(op):
201 for root, _, files in self.file_system.Walk(''): 201 results = []
202 for f in files: 202 for root, _, files in self.file_system.Walk(''):
203 futures.append(self.GetContentAndType(Join(root, f))) 203 for f in files:
204 # Also cache the extension-less version of the file if needed. 204 results.append(op(Join(root, f)))
205 base, ext = posixpath.splitext(f) 205 # Also cache the extension-less version of the file if needed.
206 if f != SITE_VERIFICATION_FILE and ext in self._default_extensions: 206 base, ext = posixpath.splitext(f)
207 futures.append(self.GetContentAndType(Join(root, base))) 207 if f != SITE_VERIFICATION_FILE and ext in self._default_extensions:
208 # TODO(kalman): Cache .zip files for each directory (if supported). 208 results.append(op(Join(root, base)))
209 return All(futures, except_pass=Exception, except_pass_log=True) 209 # TODO(kalman): Cache .zip files for each directory (if supported).
210 return results
211
212 # XXX(kalman): Need to do this stuff in APIModels as well - basically
213 # anywhere the _patch logic has been implemented. Err, sort of.
214 # Has it been implemented in here? Does it need to be?
215
216 # Immediately stat everything so that files are guaranteed to be eventually
217 # up to date. See http://crbug.com/398042 for background.
218 All(map_cron_paths(self.GetVersion)).Get()
219
220 # Update content in the future.
221 futures = [('<path_canonicalizer>', # semi-arbitrary string since there is
222 # no path associated with this Future.
223 self._path_canonicalizer.Cron())]
224 futures += map_cron_paths(lambda path: (path, self.GetContentAndType(path)))
225 def resolve():
226 for label, future in futures:
227 try: future.Get()
228 except: logging.error('%s: %s' % (label, traceback.format_exc()))
229 return Future(callback=resolve)
210 230
211 def __repr__(self): 231 def __repr__(self):
212 return 'ContentProvider of <%s>' % repr(self.file_system) 232 return 'ContentProvider of <%s>' % repr(self.file_system)
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/compiled_file_system.py ('k') | chrome/common/extensions/docs/server2/cron.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698