| OLD | NEW |
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Storage of config files.""" | 5 """Storage of config files.""" |
| 6 | 6 |
| 7 import hashlib | 7 import hashlib |
| 8 | 8 |
| 9 from google.appengine.api import app_identity | 9 from google.appengine.api import app_identity |
| 10 from google.appengine.ext import ndb | 10 from google.appengine.ext import ndb |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 ctx = ndb.get_context() | 263 ctx = ndb.get_context() |
| 264 cached = yield ctx.memcache_get(cache_key) | 264 cached = yield ctx.memcache_get(cache_key) |
| 265 if cached: | 265 if cached: |
| 266 msg = message_factory() | 266 msg = message_factory() |
| 267 msg.ParseFromString(cached) | 267 msg.ParseFromString(cached) |
| 268 raise ndb.Return(msg) | 268 raise ndb.Return(msg) |
| 269 | 269 |
| 270 cs = get_self_config_set() | 270 cs = get_self_config_set() |
| 271 messages = yield get_latest_messages_async([cs], path, message_factory) | 271 messages = yield get_latest_messages_async([cs], path, message_factory) |
| 272 msg = messages[cs] | 272 msg = messages[cs] |
| 273 yield ctx.memcache_set(cache_key, msg.SerializeToString()) | 273 yield ctx.memcache_set(cache_key, msg.SerializeToString(), time=60) |
| 274 raise ndb.Return(msg) | 274 raise ndb.Return(msg) |
| 275 | 275 |
| 276 | 276 |
| 277 def compute_hash(content): | 277 def compute_hash(content): |
| 278 """Computes Blob id by its content. | 278 """Computes Blob id by its content. |
| 279 | 279 |
| 280 See Blob docstring for Blob id format. | 280 See Blob docstring for Blob id format. |
| 281 """ | 281 """ |
| 282 sha = hashlib.sha1() | 282 sha = hashlib.sha1() |
| 283 sha.update('blob %d\0' % len(content)) | 283 sha.update('blob %d\0' % len(content)) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 295 content_hash = content_hash or compute_hash(content) | 295 content_hash = content_hash or compute_hash(content) |
| 296 | 296 |
| 297 # pylint: disable=E1120 | 297 # pylint: disable=E1120 |
| 298 if not Blob.get_by_id(content_hash): | 298 if not Blob.get_by_id(content_hash): |
| 299 yield Blob(id=content_hash, content=content).put_async() | 299 yield Blob(id=content_hash, content=content).put_async() |
| 300 raise ndb.Return(content_hash) | 300 raise ndb.Return(content_hash) |
| 301 | 301 |
| 302 | 302 |
| 303 def import_blob(content, content_hash=None): | 303 def import_blob(content, content_hash=None): |
| 304 return import_blob_async(content, content_hash=content_hash).get_result() | 304 return import_blob_async(content, content_hash=content_hash).get_result() |
| OLD | NEW |