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

Side by Side Diff: dashboard/dashboard/common/namespaced_stored_object.py

Issue 2748953003: . Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | dashboard/dashboard/common/stored_object.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """A wrapper for stored_object that separates internal and external.""" 5 """A wrapper for stored_object that separates internal and external."""
6 6
7 from google.appengine.ext import ndb
8
7 from dashboard.common import datastore_hooks 9 from dashboard.common import datastore_hooks
8 from dashboard.common import stored_object 10 from dashboard.common import stored_object
9 11
10 12
13 @ndb.synctasklet
11 def Get(key): 14 def Get(key):
12 """Gets either the external or internal copy of an object.""" 15 """Gets either the external or internal copy of an object."""
13 namespaced_key = _NamespaceKey(key) 16 result = yield GetAsync(key)
14 return stored_object.Get(namespaced_key) 17 raise ndb.Return(result)
15 18
16 19
20 @ndb.tasklet
21 def GetAsync(key):
22 namespaced_key = _NamespaceKey(key)
23 result = yield stored_object.GetAsync(namespaced_key)
24 raise ndb.Return(result)
25
26
27 @ndb.synctasklet
17 def GetExternal(key): 28 def GetExternal(key):
18 """Gets the external copy of a stored object.""" 29 """Gets the external copy of a stored object."""
19 namespaced_key = _NamespaceKey(key, datastore_hooks.EXTERNAL) 30 result = yield GetExternalAsync(key)
20 return stored_object.Get(namespaced_key) 31 raise ndb.Return(result)
21 32
22 33
34 @ndb.tasklet
35 def GetExternalAsync(key):
36 namespaced_key = _NamespaceKey(key, datastore_hooks.EXTERNAL)
37 result = yield stored_object.GetAsync(namespaced_key)
38 raise ndb.Return(result)
39
40
41 @ndb.synctasklet
23 def Set(key, value): 42 def Set(key, value):
24 """Sets the the value of a stored object, either external or internal.""" 43 """Sets the the value of a stored object, either external or internal."""
25 namespaced_key = _NamespaceKey(key) 44 yield SetAsync(key, value)
26 stored_object.Set(namespaced_key, value)
27 45
28 46
47 @ndb.tasklet
48 def SetAsync(key, value):
49 namespaced_key = _NamespaceKey(key)
50 yield stored_object.SetAsync(namespaced_key, value)
51
52
53 @ndb.synctasklet
29 def SetExternal(key, value): 54 def SetExternal(key, value):
30 """Sets the external copy of a stored object.""" 55 """Sets the external copy of a stored object."""
31 namespaced_key = _NamespaceKey(key, datastore_hooks.EXTERNAL) 56 yield SetExternalAsync(key, value)
32 stored_object.Set(namespaced_key, value)
33 57
34 58
59 @ndb.tasklet
60 def SetExternalAsync(key, value):
61 namespaced_key = _NamespaceKey(key, datastore_hooks.EXTERNAL)
62 yield stored_object.SetAsync(namespaced_key, value)
63
64
65 @ndb.synctasklet
35 def Delete(key): 66 def Delete(key):
36 """Deletes both the internal and external copy of a stored object.""" 67 """Deletes both the internal and external copy of a stored object."""
68 yield DeleteAsync(key)
69
70
71 @ndb.tasklet
72 def DeleteAsync(key):
37 internal_key = _NamespaceKey(key, namespace=datastore_hooks.INTERNAL) 73 internal_key = _NamespaceKey(key, namespace=datastore_hooks.INTERNAL)
38 external_key = _NamespaceKey(key, namespace=datastore_hooks.EXTERNAL) 74 external_key = _NamespaceKey(key, namespace=datastore_hooks.EXTERNAL)
39 stored_object.Delete(internal_key) 75 yield (
40 stored_object.Delete(external_key) 76 stored_object.DeleteAsync(internal_key),
77 stored_object.DeleteAsync(external_key))
41 78
42 79
43 def _NamespaceKey(key, namespace=None): 80 def _NamespaceKey(key, namespace=None):
44 """Prepends a namespace string to a key string.""" 81 """Prepends a namespace string to a key string."""
45 if not namespace: 82 if not namespace:
46 namespace = datastore_hooks.GetNamespace() 83 namespace = datastore_hooks.GetNamespace()
47 return '%s__%s' % (namespace, key) 84 return '%s__%s' % (namespace, key)
OLDNEW
« no previous file with comments | « no previous file | dashboard/dashboard/common/stored_object.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698