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

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

Issue 660383002: Docserver: Persist stat cache for versioned file systems (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change caching strategy, better refresh cycle synchronization Created 6 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 5
6 from base64 import b64decode 6 from base64 import b64decode
7 from itertools import izip 7 from itertools import izip
8 import json 8 import json
9 import logging 9 import logging
10 import posixpath 10 import posixpath
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 def _CreateStatInfo(json_data): 43 def _CreateStatInfo(json_data):
44 '''Returns a StatInfo object comprised of the tree ID for |json_data|, 44 '''Returns a StatInfo object comprised of the tree ID for |json_data|,
45 as well as the tree IDs for the entries in |json_data|. 45 as well as the tree IDs for the entries in |json_data|.
46 ''' 46 '''
47 tree = _ParseGitilesJson(json_data) 47 tree = _ParseGitilesJson(json_data)
48 return StatInfo(tree['id'], 48 return StatInfo(tree['id'],
49 dict((e['name'], e['id']) for e in tree['entries'])) 49 dict((e['name'], e['id']) for e in tree['entries']))
50 50
51 51
52 def _CreateIdentityFromCommit(commit):
53 return '%s/%s/%s' % (GITILES_BASE, GITILES_SRC_ROOT, commit)
54
55
52 class GitilesFileSystem(FileSystem): 56 class GitilesFileSystem(FileSystem):
53 '''Class to fetch filesystem data from the Chromium project's gitiles 57 '''Class to fetch filesystem data from the Chromium project's gitiles
54 service. 58 service.
55 ''' 59 '''
56 _logged_tokens = set() 60 _logged_tokens = set()
57 61
58 @classmethod 62 @classmethod
59 def Create(cls, branch='master', commit=None): 63 def Create(cls, branch='master', commit=None):
60 token, _ = app_identity.get_access_token(GITILES_OAUTH2_SCOPE) 64 token, _ = app_identity.get_access_token(GITILES_OAUTH2_SCOPE)
61 65
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 if IsDirectory(path): 229 if IsDirectory(path):
226 return stat_info 230 return stat_info
227 if filename not in stat_info.child_versions: 231 if filename not in stat_info.child_versions:
228 raise FileNotFoundError( 232 raise FileNotFoundError(
229 '%s from %s was not in child versions for Stat' % (filename, path)) 233 '%s from %s was not in child versions for Stat' % (filename, path))
230 return StatInfo(stat_info.child_versions[filename]) 234 return StatInfo(stat_info.child_versions[filename])
231 235
232 fetch_future = self._FetchAsync(ToDirectory(dir_) + _JSON_FORMAT) 236 fetch_future = self._FetchAsync(ToDirectory(dir_) + _JSON_FORMAT)
233 return self._ResolveFetchContent(path, fetch_future).Then(stat) 237 return self._ResolveFetchContent(path, fetch_future).Then(stat)
234 238
235 def GetIdentity(self): 239 def GetStableIdentity(self):
236 # NOTE: Do not use commit information to create the string identity. 240 '''The stable identity is always the same for GitilesFileSystems designated
237 # Doing so will mess up caching. 241 to master, even if they are pinned to a specific commit'''
238 if self._commit is None and self._branch != 'master': 242 if self._branch == 'master':
243 str_id = '%s/%s/master' % (GITILES_BASE, GITILES_SRC_ROOT)
244 elif self._commit is not None:
245 str_id = _CreateIdentityFromCommit(self._commit)
246 else:
239 str_id = '%s/%s/%s/%s' % ( 247 str_id = '%s/%s/%s/%s' % (
240 GITILES_BASE, GITILES_SRC_ROOT, GITILES_BRANCHES_PATH, self._branch) 248 GITILES_BASE, GITILES_SRC_ROOT, GITILES_BRANCHES_PATH, self._branch)
241 else:
242 str_id = '%s/%s' % (GITILES_BASE, GITILES_SRC_ROOT)
243 return '@'.join((self.__class__.__name__, StringIdentity(str_id))) 249 return '@'.join((self.__class__.__name__, StringIdentity(str_id)))
250
251 def GetUnstableIdentity(self):
252 '''The unstable identity always tracks the commit ID if set.'''
253 if self._commit is not None:
254 return '@'.join((self.__class__.__name__, StringIdentity(
255 _CreateIdentityFromCommit(self._commit))))
256 return self.GetStableIdentity()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698