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

Unified Diff: appengine/isolate/model.py

Issue 1866753008: Add ability to linkify hashes on isolate server (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: Address feedback round 2 Created 4 years, 8 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: appengine/isolate/model.py
diff --git a/appengine/isolate/model.py b/appengine/isolate/model.py
index 123d6ba436dfb578408bffbfcd977ca2c30b4632..b92786864266c76fc70e14437d1d2224a530bccb 100644
--- a/appengine/isolate/model.py
+++ b/appengine/isolate/model.py
@@ -135,6 +135,30 @@ def entry_key_from_id(key_id):
parent=datastore_utils.shard_key(hash_key, N, 'ContentShard'))
+def get_content(namespace, hash_key):
+ """Returns the content from either memcache or datastore.
M-A Ruel 2016/04/14 19:22:36 Returns the content from either memcache or datast
kjlubick 2016/04/14 19:59:07 Done.
+
+ This does NOT return data from GCS, it is up to the client to do that.
+
+ The first argument in the tuple is the content, the second is either
M-A Ruel 2016/04/14 19:22:36 Returns: tuple(content, ContentEntry) At most
kjlubick 2016/04/14 19:59:08 Done.
+ None, if loaded from memcache, or the entity, if loaded from datastore.
+
+ Raises LookupError if the content cannot be found.
+ Raises ValueError if the hash_key is invalid.
+ """
+ memcache_entry = memcache.get(hash_key, namespace='table_%s' % namespace)
+ if memcache_entry is not None:
+ return (memcache_entry, None)
+ else:
+ # Raises ValueError
+ key = get_entry_key(namespace, hash_key)
+ entity = key.get()
+ if entity is None:
+ raise LookupError("namespace %s, key %s does not refer to anything" %
+ (namespace, hash_key))
+ return (entity.content, entity)
+
+
def expiration_jitter(now, expiration):
"""Returns expiration/next_tag pair to set in a ContentEntry."""
jittered = random.uniform(1, 1.2) * expiration

Powered by Google App Engine
This is Rietveld 408576698