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

Side by Side Diff: filter/dscache/context.go

Issue 2302743002: Interface update, per-method Contexts. (Closed)
Patch Set: Lightning talk licenses. Created 4 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 unified diff | Download patch
« no previous file with comments | « filter/dsQueryBatch/filter_test.go ('k') | filter/dscache/ds.go » ('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 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 package dscache 5 package dscache
6 6
7 import ( 7 import (
8 ds "github.com/luci/gae/service/datastore" 8 ds "github.com/luci/gae/service/datastore"
9 » "github.com/luci/gae/service/info" 9
10 » mc "github.com/luci/gae/service/memcache"
11 "github.com/luci/luci-go/common/data/rand/mathrand" 10 "github.com/luci/luci-go/common/data/rand/mathrand"
11
12 "golang.org/x/net/context" 12 "golang.org/x/net/context"
13 ) 13 )
14 14
15 type key int 15 type key int
16 16
17 var dsTxnCacheKey key 17 var dsTxnCacheKey key
18 18
19 // FilterRDS installs a caching RawDatastore filter in the context. 19 // FilterRDS installs a caching RawDatastore filter in the context.
20 // 20 //
21 // It does nothing if IsGloballyEnabled returns false. That way it is possible 21 // It does nothing if IsGloballyEnabled returns false. That way it is possible
(...skipping 15 matching lines...) Expand all
37 return c 37 return c
38 } 38 }
39 return AlwaysFilterRDS(c, shardsForKey) 39 return AlwaysFilterRDS(c, shardsForKey)
40 } 40 }
41 41
42 // AlwaysFilterRDS installs a caching RawDatastore filter in the context. 42 // AlwaysFilterRDS installs a caching RawDatastore filter in the context.
43 // 43 //
44 // Unlike FilterRDS it doesn't check GlobalConfig via IsGloballyEnabled call, 44 // Unlike FilterRDS it doesn't check GlobalConfig via IsGloballyEnabled call,
45 // assuming caller already knows whether filter should be applied or not. 45 // assuming caller already knows whether filter should be applied or not.
46 func AlwaysFilterRDS(c context.Context, shardsForKey func(*ds.Key) int) context. Context { 46 func AlwaysFilterRDS(c context.Context, shardsForKey func(*ds.Key) int) context. Context {
47 » return ds.AddRawFilters(c, func(c context.Context, ds ds.RawInterface) d s.RawInterface { 47 » return ds.AddRawFilters(c, func(c context.Context, rds ds.RawInterface) ds.RawInterface {
48 » » i := info.Get(c) 48 » » kc := ds.GetKeyContext(c)
49 » » ns, _ := i.GetNamespace()
50 49
51 sc := &supportContext{ 50 sc := &supportContext{
52 » » » i.AppID(), 51 » » » kc.AppID,
53 » » » ns, 52 » » » kc.Namespace,
54 c, 53 c,
55 mc.Get(c),
56 mathrand.Get(c), 54 mathrand.Get(c),
57 shardsForKey, 55 shardsForKey,
58 } 56 }
59 57
60 v := c.Value(dsTxnCacheKey) 58 v := c.Value(dsTxnCacheKey)
61 if v == nil { 59 if v == nil {
62 » » » return &dsCache{ds, sc} 60 » » » return &dsCache{rds, sc}
63 } 61 }
64 » » return &dsTxnCache{ds, v.(*dsTxnState), sc} 62 » » return &dsTxnCache{rds, v.(*dsTxnState), sc}
65 }) 63 })
66 } 64 }
OLDNEW
« no previous file with comments | « filter/dsQueryBatch/filter_test.go ('k') | filter/dscache/ds.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698