Index: chrome/common/extensions/docs/server2/handler.py |
diff --git a/chrome/common/extensions/docs/server2/handler.py b/chrome/common/extensions/docs/server2/handler.py |
index a89cdcf32a741986436f93ba4bdda79629f7cb0c..eaa6f9f0032f5a29712886b00aaa7975835d8631 100644 |
--- a/chrome/common/extensions/docs/server2/handler.py |
+++ b/chrome/common/extensions/docs/server2/handler.py |
@@ -32,11 +32,13 @@ from sidenav_data_source import SidenavDataSource |
from subversion_file_system import SubversionFileSystem |
from template_data_source import TemplateDataSource |
from third_party.json_schema_compiler.model import UnixName |
+from chrome_version_data_source import ChromeVersionDataSource |
+from availability_data_source import AvailabilityDataSource |
import url_constants |
# Increment this version to force the server to reload all pages in the first |
# cron job that is run. |
-_VERSION = 1 |
+_VERSION = 2 |
# The default channel to serve docs for if no channel is specified. |
_DEFAULT_CHANNEL = 'stable' |
@@ -46,13 +48,24 @@ BRANCH_UTILITY = BranchUtility(url_constants.OMAHA_PROXY_URL, |
AppEngineUrlFetcher(None), |
BRANCH_UTILITY_MEMCACHE) |
+AVAILABILITY_DATA_SOURCE_MEMCACHE = InMemoryObjectStore( |
+ 'availability_data_source') |
+ |
+CHROME_VERSION_DATA_SOURCE_MEMCACHE = InMemoryObjectStore( |
+ 'chrome_version_data_source') |
+CHROME_VERSION_DATA_SOURCE = ChromeVersionDataSource( |
+ url_constants.OMAHA_BETA_HISTORY, |
+ AppEngineUrlFetcher(None), |
+ CHROME_VERSION_DATA_SOURCE_MEMCACHE) |
+ |
GITHUB_MEMCACHE = InMemoryObjectStore('github') |
GITHUB_FILE_SYSTEM = GithubFileSystem( |
AppEngineUrlFetcher(url_constants.GITHUB_URL), |
GITHUB_MEMCACHE, |
AppEngineBlobstore()) |
-GITHUB_COMPILED_FILE_SYSTEM = CompiledFileSystem.Factory(GITHUB_FILE_SYSTEM, |
- GITHUB_MEMCACHE) |
+GITHUB_COMPILED_FILE_SYSTEM = CompiledFileSystem.Factory( |
cduvall
2013/03/21 18:43:53
revert
epeterson
2013/03/25 19:35:11
Done.
|
+ GITHUB_FILE_SYSTEM, |
+ GITHUB_MEMCACHE) |
EXTENSIONS_PATH = 'chrome/common/extensions' |
DOCS_PATH = 'docs' |
@@ -65,6 +78,7 @@ PRIVATE_TEMPLATE_PATH = TEMPLATE_PATH + '/private' |
EXAMPLES_PATH = DOCS_PATH + '/examples' |
JSON_PATH = TEMPLATE_PATH + '/json' |
+ |
cduvall
2013/03/21 18:43:53
Remove newline
epeterson
2013/03/25 19:35:11
Done.
|
# Global cache of instances because Handler is recreated for every request. |
SERVER_INSTANCES = {} |
@@ -84,19 +98,22 @@ def _CreateMemcacheFileSystem(branch, branch_memcache): |
return MemcacheFileSystem(SubversionFileSystem(fetcher, stat_fetcher), |
branch_memcache) |
-_default_branch = BRANCH_UTILITY.GetBranchNumberForChannelName(_DEFAULT_CHANNEL) |
+_default_branch = BRANCH_UTILITY.GetBranchAndVersionForChannelName( |
+ _DEFAULT_CHANNEL)['branch'] |
APPS_MEMCACHE = InMemoryObjectStore(_default_branch) |
APPS_FILE_SYSTEM = _CreateMemcacheFileSystem(_default_branch, APPS_MEMCACHE) |
APPS_COMPILED_FILE_SYSTEM = CompiledFileSystem.Factory( |
APPS_FILE_SYSTEM, |
- APPS_MEMCACHE).Create(_SplitFilenameUnix, compiled_fs.APPS_FS) |
+ APPS_MEMCACHE).Create(_SplitFilenameUnix, |
cduvall
2013/03/21 18:43:53
revert
epeterson
2013/03/25 19:35:11
Done.
|
+ compiled_fs.APPS_FS) |
EXTENSIONS_MEMCACHE = InMemoryObjectStore(_default_branch) |
EXTENSIONS_FILE_SYSTEM = _CreateMemcacheFileSystem(_default_branch, |
EXTENSIONS_MEMCACHE) |
EXTENSIONS_COMPILED_FILE_SYSTEM = CompiledFileSystem.Factory( |
EXTENSIONS_FILE_SYSTEM, |
- EXTENSIONS_MEMCACHE).Create(_SplitFilenameUnix, compiled_fs.EXTENSIONS_FS) |
+ EXTENSIONS_MEMCACHE).Create(_SplitFilenameUnix, |
cduvall
2013/03/21 18:43:53
revert
epeterson
2013/03/25 19:35:11
Done.
|
+ compiled_fs.EXTENSIONS_FS) |
KNOWN_ISSUES_DATA_SOURCE = KnownIssuesDataSource( |
InMemoryObjectStore('KnownIssues'), |
@@ -106,7 +123,11 @@ def _MakeInstanceKey(branch, number): |
return '%s/%s' % (branch, number) |
def _GetInstanceForBranch(channel_name, local_path): |
- branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel_name) |
+ branchAndVersion = BRANCH_UTILITY.GetBranchAndVersionForChannelName( |
cduvall
2013/03/21 18:43:53
use unix_hacker style names.
but this can just be
epeterson
2013/03/25 19:35:11
I reworked this. branchAndVersion actually contain
|
+ channel_name) |
+ |
+ branch = branchAndVersion['branch'] |
+ version = branchAndVersion['version'] |
# The key for the server is a tuple of |channel_name| with |branch|, since |
# sometimes stable and beta point to the same branch. |
@@ -117,14 +138,21 @@ def _GetInstanceForBranch(channel_name, local_path): |
branch_memcache = InMemoryObjectStore(branch) |
file_system = _CreateMemcacheFileSystem(branch, branch_memcache) |
- cache_factory = CompiledFileSystem.Factory(file_system, branch_memcache) |
+ cache_factory = CompiledFileSystem.Factory( |
cduvall
2013/03/21 18:43:53
revert
epeterson
2013/03/25 19:35:11
Done.
|
+ file_system, |
+ branch_memcache) |
api_list_data_source_factory = APIListDataSource.Factory(cache_factory, |
file_system, |
API_PATH, |
PUBLIC_TEMPLATE_PATH) |
+ availability_data_source = AvailabilityDataSource( |
+ CHROME_VERSION_DATA_SOURCE, |
+ version, |
+ AVAILABILITY_DATA_SOURCE_MEMCACHE) |
api_data_source_factory = APIDataSource.Factory( |
cache_factory, |
- API_PATH) |
+ API_PATH, |
+ availability_data_source) |
# Give the ReferenceResolver a memcache, to speed up the lookup of |
# duplicate $refs. |
@@ -160,11 +188,51 @@ def _GetInstanceForBranch(channel_name, local_path): |
cache_factory, |
ref_resolver_factory, |
PUBLIC_TEMPLATE_PATH, |
- PRIVATE_TEMPLATE_PATH) |
+ PRIVATE_TEMPLATE_PATH, |
+ BRANCH_UTILITY.GetBranchAndVersionForAllChannels()) |
example_zipper = ExampleZipper(file_system, |
cache_factory, |
DOCS_PATH) |
+ #hacky solution for creating a bunch of memcaches in ChromeVersionDataSource |
+ def _CreateMemcacheForBranch(branch_number): |
+ """Passed to the global instance of chromeVersionDataSource. Allows for |
+ the creation of api_data_sources linked to |branch_number|, which is the |
+ maximum branch number from a given version of chrome. |
+ """ |
+ branch_memcache = InMemoryObjectStore(branch_number) |
+ file_system = _CreateMemcacheFileSystem(branch_number, branch_memcache) |
+ cache_factory = CompiledFileSystem.Factory( |
+ file_system, |
+ branch_memcache, |
+ branch_number) |
+ api_list_data_source_factory = APIListDataSource.Factory( |
+ cache_factory, |
+ file_system, |
+ API_PATH, |
+ PUBLIC_TEMPLATE_PATH) |
+ api_data_source_factory = APIDataSource.Factory(cache_factory, |
+ API_PATH) |
+ ref_resolver_factory = ReferenceResolver.Factory( |
+ api_data_source_factory, |
+ api_list_data_source_factory, |
+ branch_memcache) |
+ api_data_source_factory.SetReferenceResolverFactory(ref_resolver_factory) |
+ samples_data_source_factory = SamplesDataSource.Factory( |
+ channel_name, |
+ file_system, |
+ GITHUB_FILE_SYSTEM, |
+ cache_factory, |
+ GITHUB_COMPILED_FILE_SYSTEM, |
+ ref_resolver_factory, |
+ EXAMPLES_PATH) |
+ api_data_source_factory.SetSamplesDataSourceFactory( |
+ samples_data_source_factory) |
+ return api_data_source_factory.Create(None) |
+ |
+ CHROME_VERSION_DATA_SOURCE.SetCreateMemcacheForBranch( |
cduvall
2013/03/21 18:43:53
Can you just pass this into the ChromeVersionDataS
epeterson
2013/03/25 19:35:11
Done. Yep.
|
+ _CreateMemcacheForBranch) |
+ |
instance = ServerInstance(template_data_source_factory, |
example_zipper, |
cache_factory) |
@@ -262,11 +330,12 @@ class Handler(webapp.RequestHandler): |
# be called. The same is then done separately with the apps samples page, |
# since it pulls its data from Github. |
channel = path.split('/')[-1] |
- branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel) |
+ branch = BRANCH_UTILITY.GetBranchAndVersionForChannelName(channel)['branch'] |
logging.info('Running cron job for %s.' % branch) |
branch_memcache = InMemoryObjectStore(branch) |
file_system = _CreateMemcacheFileSystem(branch, branch_memcache) |
- factory = CompiledFileSystem.Factory(file_system, branch_memcache) |
+ factory = CompiledFileSystem.Factory(file_system, |
cduvall
2013/03/21 18:43:53
revert
epeterson
2013/03/25 19:35:11
Done.
|
+ branch_memcache) |
needs_render = self._ValueHolder(False) |
invalidation_cache = factory.Create(lambda _, __: needs_render.Set(True), |