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

Unified Diff: impl/memory/context.go

Issue 1309803004: Add transaction buffer filter. (Closed) Base URL: https://github.com/luci/gae.git@add_query_support
Patch Set: make data flow clearer, implement Count Created 5 years, 3 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: impl/memory/context.go
diff --git a/impl/memory/context.go b/impl/memory/context.go
index 286736b4ade8e23c3c2e0c90ef5a508f20715d01..6108e02cbdcbfac51122f37dd97b7dbe2df2b48c 100644
--- a/impl/memory/context.go
+++ b/impl/memory/context.go
@@ -27,10 +27,10 @@ type memContext []memContextObj
var _ = memContextObj((memContext)(nil))
-func newMemContext() memContext {
+func newMemContext(aid string) memContext {
return memContext{
newTaskQueueData(),
- newDataStoreData(),
+ newDataStoreData(aid),
}
}
@@ -88,27 +88,35 @@ func (m memContext) applyTxn(c context.Context, txnCtxObj memContextObj) {
}
}
-// Use adds implementations for the following gae interfaces to the
+// Use calls UseWithAppID with the appid of "dev~app"
+func Use(c context.Context) context.Context {
+ return UseWithAppID(c, "dev~app")
+}
+
+// UseWithAppID adds implementations for the following gae interfaces to the
// context:
// * gae.Datastore
// * gae.TaskQueue
// * gae.Memcache
// * gae.GlobalInfo
//
+// The application id wil be set to 'aid', and will not be modifiable in this
+// context.
+//
// These can be retrieved with the gae.Get functions.
//
// The implementations are all backed by an in-memory implementation, and start
// with an empty state.
//
// Using this more than once per context.Context will cause a panic.
-func Use(c context.Context) context.Context {
+func UseWithAppID(c context.Context, aid string) context.Context {
iannucci 2015/09/29 04:43:27 This was so that the in-memory buffered transactio
if c.Value(memContextKey) != nil {
panic(errors.New("memory.Use: called twice on the same Context"))
}
c = context.WithValue(
- context.WithValue(c, memContextKey, newMemContext()),
- giContextKey, &globalInfoData{})
- return useTQ(useRDS(useMC(useGI(c))))
+ context.WithValue(c, memContextKey, newMemContext(aid)),
+ giContextKey, &globalInfoData{appid: aid})
+ return useTQ(useRDS(useMC(useGI(c, aid))))
}
func cur(c context.Context) (p memContext) {

Powered by Google App Engine
This is Rietveld 408576698