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

Unified Diff: chrome/common/extensions/docs/server2/intro_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/intro_data_source.py
diff --git a/chrome/common/extensions/docs/server2/intro_data_source.py b/chrome/common/extensions/docs/server2/intro_data_source.py
index 14315ad784ed4b9026699b46a986c3f166278ee1..d2a1717ce7c04709129f572c284c8607de707ca9 100644
--- a/chrome/common/extensions/docs/server2/intro_data_source.py
+++ b/chrome/common/extensions/docs/server2/intro_data_source.py
@@ -5,6 +5,7 @@
from HTMLParser import HTMLParser
import logging
import re
+import time
from docs_server_utils import FormatKey
from file_system import FileNotFoundError
@@ -53,28 +54,43 @@ class _IntroParser(HTMLParser):
self._current_heading['title'] += data
class IntroDataSource(object):
+ class Factory(object):
+ def __init__(self, cache_builder, base_paths):
+ self._cache = cache_builder.build(self._MakeIntroDict)
+ self._base_paths = base_paths
+ self._intro_regex = re.compile('<h1[^>.]*?>.*?</h1>', flags=re.DOTALL)
+
+ def _MakeIntroDict(self, intro):
+ parser = _IntroParser()
+ parser.feed(intro)
+ intro = re.sub(self._intro_regex, '', intro, count=1)
+ return {
+ 'intro': Handlebar(intro),
+ 'toc': parser.toc,
+ 'title': parser.page_title
+ }
+
+ def Create(self):
+ return IntroDataSource(self._cache.ScopeToRequest(), self._base_paths)
+
"""This class fetches the intros for a given API. From this intro, a table
of contents dictionary is created, which contains the headings in the intro.
"""
- def __init__(self, cache_builder, base_paths):
- self._cache = cache_builder.build(self._MakeIntroDict)
+ def __init__(self, cache, base_paths):
+ self._cache = cache
self._base_paths = base_paths
- self._intro_regex = re.compile('<h1[^>.]*?>.*?</h1>', flags=re.DOTALL)
-
- def _MakeIntroDict(self, intro):
- parser = _IntroParser()
- parser.feed(intro)
- intro = re.sub(self._intro_regex, '', intro, count=1)
- return {
- 'intro': Handlebar(intro),
- 'toc': parser.toc,
- 'title': parser.page_title
- }
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("IntroDataSource: %sms", (time.time() - start_time) * 1000)
+
+ def _do_get(self, key):
real_path = FormatKey(key)
error = None
for base_path in self._base_paths:
« no previous file with comments | « chrome/common/extensions/docs/server2/handler.py ('k') | chrome/common/extensions/docs/server2/local_file_system.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698