Index: impl/prod/context.go |
diff --git a/impl/prod/context.go b/impl/prod/context.go |
index 11bd6c24e33189a6c1e815b975a15ee2ff2c7b56..80d24e224f5b0dbdb3f16c5f51c80da7a924f94e 100644 |
--- a/impl/prod/context.go |
+++ b/impl/prod/context.go |
@@ -7,6 +7,7 @@ package prod |
import ( |
"net/http" |
+ "github.com/luci/gae/service/info" |
"golang.org/x/net/context" |
"google.golang.org/appengine" |
) |
@@ -14,8 +15,9 @@ import ( |
type key int |
var ( |
- prodContextKey key |
- probeCacheKey key = 1 |
+ prodContextKey key |
+ prodContextNoTxnKey key = 1 |
+ probeCacheKey key = 2 |
) |
// AEContext retrieves the raw "google.golang.org/appengine" compatible Context. |
@@ -24,6 +26,17 @@ func AEContext(c context.Context) context.Context { |
return aeCtx |
} |
+// AEContextNoTxn retrieves the raw "google.golang.org/appengine" compatible |
+// Context that's not part of a transaction. |
+func AEContextNoTxn(c context.Context) context.Context { |
+ aeCtx, _ := c.Value(prodContextNoTxnKey).(context.Context) |
+ aeCtx, err := appengine.Namespace(aeCtx, info.Get(c).GetNamespace()) |
+ if err != nil { |
+ panic(err) |
+ } |
+ return aeCtx |
+} |
+ |
// Use adds production implementations for all the gae services to the |
// context. |
// |
@@ -40,5 +53,6 @@ func AEContext(c context.Context) context.Context { |
func Use(c context.Context, r *http.Request) context.Context { |
aeCtx := appengine.NewContext(r) |
c = context.WithValue(c, prodContextKey, aeCtx) |
+ c = context.WithValue(c, prodContextNoTxnKey, aeCtx) |
return useUser(useURLFetch(useRDS(useMC(useTQ(useGI(c)))))) |
} |