Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: globals/get_browser_versions.py

Issue 6556375547117568: Issue 2432 - Cache browser versions during page generation (Closed)
Patch Set: Created May 18, 2015, 1:04 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: globals/get_browser_versions.py
===================================================================
--- a/globals/get_browser_versions.py
+++ b/globals/get_browser_versions.py
@@ -26,6 +26,8 @@
</app>
</request>'''
+cache = {}
+
def get_mozilla_version(product, origin_version, channel,
minor=False, subdomain='aus4', origin_build='-',
attribute='appVersion', platform='WINNT_x86-msvc'):
@@ -157,6 +159,10 @@
@contextfunction
def get_browser_versions(context, browser):
+ versions = cache.get(browser)
+ if versions:
+ return versions
+
func = BROWSERS[browser]
exc_info = None
try:
@@ -167,13 +173,13 @@
filename = os.path.join(context['source'].get_cache_dir(), 'browsers.json')
with open_cache_file(filename) as file:
try:
- cache = json.load(file)
+ persistent_cache = json.load(file)
except ValueError:
if file.tell() > 0:
raise
- cache = {}
+ persistent_cache = {}
- cached_versions = cache.get(browser)
+ cached_versions = persistent_cache.get(browser)
if exc_info:
if not cached_versions:
raise exc_info[0], exc_info[1], exc_info[2]
@@ -203,13 +209,14 @@
key=lambda ver: map(int, ver.split('.'))
)
- cache[browser] = versions
+ persistent_cache[browser] = versions
file.seek(0)
- json.dump(cache, file)
+ json.dump(persistent_cache, file)
file.truncate()
if not versions['previous']:
logging.warning("Couldn't determine previous browser version, "
'please set %s.previous in %s', browser, filename)
+ cache[browser] = versions
return versions
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld