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

Side by Side Diff: chrome/common/extensions/docs/server2/persistent_object_store.py

Issue 1151283007: Docserver overhaul: Gitiles away from me. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove inform_users template to fix presubmit failure (it's now a redirect) Created 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 from appengine_wrappers import db
6 from datastore_models import PersistentObjectStoreItem
7 from environment import IsDevServer
8 from future import All, Future
9 from object_store import ObjectStore
10
11
12 class PersistentObjectStore(ObjectStore):
13 '''Stores data persistently using the AppEngine Datastore API.
14 '''
15 def __init__(self, namespace):
16 self._namespace = namespace
17
18 def SetMulti(self, mapping):
19 rpcs = [db.put_async(
20 PersistentObjectStoreItem.CreateItem(self._namespace, key, value))
21 for key, value in mapping.iteritems()]
22 # If running the dev server, the futures don't complete until the server is
23 # *quitting*. This is annoying. Flush now.
24 if IsDevServer():
25 [rpc.wait() for rpc in rpcs]
26 return All(Future(callback=lambda: rpc.get_result()) for rpc in rpcs)
27
28 def GetMulti(self, keys):
29 db_futures = dict(
30 (k, db.get_async(
31 PersistentObjectStoreItem.CreateKey(self._namespace, k)))
32 for k in keys)
33 def resolve():
34 return dict((key, future.get_result().GetValue())
35 for key, future in db_futures.iteritems()
36 if future.get_result() is not None)
37 return Future(callback=resolve)
38
39 def DelMulti(self, keys):
40 futures = []
41 for key in keys:
42 futures.append(db.delete_async(
43 PersistentObjectStoreItem.CreateKey(self._namespace, key)))
44 # If running the dev server, the futures don't complete until the server is
45 # *quitting*. This is annoying. Flush now.
46 if IsDevServer():
47 [future.wait() for future in futures]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698