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

Unified Diff: appengine/config_service/projects.py

Issue 2932733002: config_service: optimize projects.get_metadata (Closed)
Patch Set: self review Created 3 years, 6 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
« 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: appengine/config_service/projects.py
diff --git a/appengine/config_service/projects.py b/appengine/config_service/projects.py
index c8a45025bb06bde0cab1ab04405fc59848409fbc..b20155c7124112c505be55226cc9fb1262a5ac6c 100644
--- a/appengine/config_service/projects.py
+++ b/appengine/config_service/projects.py
@@ -6,6 +6,7 @@
import logging
+from google.appengine.api import memcache
from google.appengine.ext import ndb
from google.appengine.ext.ndb import msgprop
from protorpc import messages
@@ -96,9 +97,38 @@ def get_metadata(project_ids):
The project metadata stored in project.cfg files in each project.
"""
- return _get_project_configs(
- project_ids, common.PROJECT_METADATA_FILENAME,
- project_config_pb2.ProjectCfg)
+ cache_ns = 'projects.get_metadata'
+ cache_map = memcache.get_multi(project_ids, namespace=cache_ns)
+ result = {}
+ missing = []
+ for pid in project_ids:
+ if pid in cache_map:
+ # cache hit
+ binary = cache_map[pid]
+ if binary is None:
+ # project does not exist
+ result[pid] = None
+ else:
+ cfg = project_config_pb2.ProjectCfg()
+ cfg.ParseFromString(binary)
+ result[pid] = cfg
+ else:
+ # cache miss
+ missing.append(pid)
+
+ if missing:
+ fetched = _get_project_configs(
+ missing, common.PROJECT_METADATA_FILENAME,
+ project_config_pb2.ProjectCfg)
+ result.update(fetched) # at this point result must have all project ids
+ # Cache metadata for 10 min. In practice, it never changes.
+ cache_map = {
+ pid: cfg.SerializeToString() if cfg else None
+ for pid, cfg in fetched.iteritems()
+ }
+ memcache.set_multi(cache_map, namespace=cache_ns, time=60 * 10)
+
+ return result
def get_refs(project_ids):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698