Index: chrome/common/extensions/docs/server2/render_servlet.py |
diff --git a/chrome/common/extensions/docs/server2/render_servlet.py b/chrome/common/extensions/docs/server2/render_servlet.py |
index be310d838290441de8337cbc64c3d3d2480eabad..ac473414c79f88814c3455d1f3a6abe2ca1e48b1 100644 |
--- a/chrome/common/extensions/docs/server2/render_servlet.py |
+++ b/chrome/common/extensions/docs/server2/render_servlet.py |
@@ -14,6 +14,7 @@ from file_system import FileNotFoundError |
from server_instance import ServerInstance |
from servlet import Servlet, Response |
import svn_constants |
+from third_party.json_schema_compiler.memoize import memoize |
_DEFAULT_CHANNEL = 'stable' |
@@ -23,24 +24,30 @@ def _IsBinaryMimetype(mimetype): |
return any(mimetype.startswith(prefix) |
for prefix in ['audio', 'image', 'video']) |
-def AlwaysOnline(fn): |
- '''A function decorator which forces the rendering to be always online rather |
- than the default offline behaviour. Useful for testing. |
- ''' |
- def impl(*args, **optargs): |
- global _ALWAYS_ONLINE |
- was_always_online = _ALWAYS_ONLINE |
- try: |
- _ALWAYS_ONLINE = True |
- return fn(*args, **optargs) |
- finally: |
- _ALWAYS_ONLINE = was_always_online |
- return impl |
+@memoize |
+def _GetOrCreateServerInstance(channel): |
+ return ServerInstance.CreateOffline(channel) |
class RenderServlet(Servlet): |
'''Servlet which renders templates. |
''' |
def Get(self, server_instance=None): |
+ # A note about |server_instance|: |
+ # |
+ # AppEngine instances should never need to call out to SVN. That should |
+ # only ever be done by the cronjobs, which then write the result into |
+ # DataStore, which is as far as instances look. To enable this, crons can |
+ # pass a custom (presumably online) ServerInstance into Get(). |
+ # |
+ # Why? SVN is slow and a bit flaky. Cronjobs failing is annoying but |
+ # temporary. Instances failing affects users, and is really bad. |
+ # |
+ # Anyway - to enforce this, we actually don't give instances access to SVN. |
+ # If anything is missing from datastore, it'll be a 404. If the cronjobs |
+ # don't manage to catch everything - uhoh. On the other hand, we'll figure |
+ # it out pretty soon, and it also means that legitimate 404s are caught |
+ # before a round trip to SVN. |
+ |
path_with_channel, headers = (self._request.path.lstrip('/'), |
self._request.headers) |
@@ -59,25 +66,8 @@ class RenderServlet(Servlet): |
if channel is None: |
channel = _DEFAULT_CHANNEL |
- # AppEngine instances should never need to call out to SVN. That should |
- # only ever be done by the cronjobs, which then write the result into |
- # DataStore, which is as far as instances look. To enable this, crons can |
- # pass a custom (presumably online) ServerInstance into Get(). |
- # |
- # Why? SVN is slow and a bit flaky. Cronjobs failing is annoying but |
- # temporary. Instances failing affects users, and is really bad. |
- # |
- # Anyway - to enforce this, we actually don't give instances access to SVN. |
- # If anything is missing from datastore, it'll be a 404. If the cronjobs |
- # don't manage to catch everything - uhoh. On the other hand, we'll figure |
- # it out pretty soon, and it also means that legitimate 404s are caught |
- # before a round trip to SVN. |
if server_instance is None: |
- # The ALWAYS_ONLINE thing is for tests and preview.py that shouldn't need |
- # to run the cron before rendering things. |
- constructor = (ServerInstance.CreateOnline if _ALWAYS_ONLINE else |
- ServerInstance.GetOrCreateOffline) |
- server_instance = constructor(channel) |
+ server_instance = _GetOrCreateServerInstance(channel) |
canonical_path = server_instance.path_canonicalizer.Canonicalize(path) |
if path != canonical_path: |