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

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

Issue 10834329: Extension docs server: many changes to bring down the latency of the server, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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/api_list_data_source.py
diff --git a/chrome/common/extensions/docs/server2/api_list_data_source.py b/chrome/common/extensions/docs/server2/api_list_data_source.py
index 8d00f6652f85647264d06e885a79cf72b6a886b9..484122c62ece9d84f1626ecb26b3de1a1eb425bd 100644
--- a/chrome/common/extensions/docs/server2/api_list_data_source.py
+++ b/chrome/common/extensions/docs/server2/api_list_data_source.py
@@ -4,6 +4,7 @@
import logging
import os
+import time
from file_system import FileNotFoundError
import third_party.json_schema_compiler.model as model
@@ -15,51 +16,68 @@ IGNORED_FILES = [
]
class APIListDataSource(object):
+ class Factory(object):
+ def __init__(self, cache_builder, file_system, api_path, public_path):
+ self._cache = cache_builder.build(self._ListAPIs)
+ self._file_system = file_system
+ def Normalize(string):
+ return string if string.endswith('/') else (string + '/')
+ self._api_path = Normalize(api_path)
+ self._public_path = Normalize(public_path)
+
+ def _GetAPIsInSubdirectory(self, api_names, doc_type):
+ public_templates = self._file_system.ReadSingle(
+ self._public_path + doc_type + '/')
+ template_names = [os.path.splitext(name)[0]
+ for name in public_templates]
+ experimental_apis = []
+ chrome_apis = []
+ for template_name in sorted(template_names):
+ if template_name in IGNORED_FILES:
+ continue
+ if model.UnixName(template_name) in api_names:
+ if template_name.startswith('experimental'):
+ experimental_apis.append({
+ 'name': template_name.replace('_', '.')
+ })
+ else:
+ chrome_apis.append({ 'name': template_name.replace('_', '.') })
+ chrome_apis[-1]['last'] = True
+ experimental_apis[-1]['last'] = True
+ return {
+ 'chrome': chrome_apis,
+ 'experimental': experimental_apis
+ }
+
+ def _ListAPIs(self, apis):
+ api_names = set(SanitizeAPIName(name, self._api_path) for name in apis)
+ return {
+ 'apps': self._GetAPIsInSubdirectory(api_names, 'apps'),
+ 'extensions': self._GetAPIsInSubdirectory(api_names, 'extensions')
+ }
+
+ def Create(self):
+ return APIListDataSource(self._cache.ScopeToRequest(), self._api_path)
+
""" This class creates a list of chrome.* APIs and chrome.experimental.* APIs
that are used in the api_index.html and experimental.html pages.
"""
- def __init__(self, cache_builder, file_system, api_path, public_path):
- self._cache = cache_builder.build(self._ListAPIs)
- self._file_system = file_system
- self._api_path = api_path + '/'
- self._public_path = public_path + '/'
-
- def _GetAPIsInSubdirectory(self, api_names, doc_type):
- public_templates = self._file_system.ReadSingle(
- self._public_path + doc_type + '/')
- template_names = [os.path.splitext(name)[0]
- for name in public_templates]
- experimental_apis = []
- chrome_apis = []
- for template_name in sorted(template_names):
- if template_name in IGNORED_FILES:
- continue
- if model.UnixName(template_name) in api_names:
- if template_name.startswith('experimental'):
- experimental_apis.append({
- 'name': template_name.replace('_', '.')
- })
- else:
- chrome_apis.append({ 'name': template_name.replace('_', '.') })
- chrome_apis[-1]['last'] = True
- experimental_apis[-1]['last'] = True
- return {
- 'chrome': chrome_apis,
- 'experimental': experimental_apis
- }
-
- def _ListAPIs(self, apis):
- api_names = set(SanitizeAPIName(name, self._api_path) for name in apis)
- return {
- 'apps': self._GetAPIsInSubdirectory(api_names, 'apps'),
- 'extensions': self._GetAPIsInSubdirectory(api_names, 'extensions')
- }
+ def __init__(self, cache, api_path):
+ self._cache = cache
+ self._api_path = api_path
def __getitem__(self, key):
return self.get(key)
def get(self, key):
+ start_time = time.time()
+ try:
+ return self._do_get(key)
+ finally:
+ logging.info("ApiListDataSource: %sms", (time.time() - start_time) * 1000)
+
+ def _do_get(self, key):
try:
return self._cache.GetFromFileListing(self._api_path)[key]
except FileNotFoundError as e:
- raise ValueError(str(e) + ': Error listing files for "%s".' % key)
+ raise ValueError('%s: Error listing files for "%s".' % (e, key))
« no previous file with comments | « chrome/common/extensions/docs/server2/api_data_source.py ('k') | chrome/common/extensions/docs/server2/app.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698