OLD | NEW |
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 package featureBreaker | 5 package featureBreaker |
6 | 6 |
7 import ( | 7 import ( |
8 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
9 | 9 |
10 ds "github.com/luci/gae/service/datastore" | 10 ds "github.com/luci/gae/service/datastore" |
(...skipping 22 matching lines...) Expand all Loading... |
33 }) | 33 }) |
34 return curs, err | 34 return curs, err |
35 } | 35 } |
36 | 36 |
37 func (r *dsState) Run(q *ds.FinalizedQuery, cb ds.RawRunCB) error { | 37 func (r *dsState) Run(q *ds.FinalizedQuery, cb ds.RawRunCB) error { |
38 return r.run(func() error { | 38 return r.run(func() error { |
39 return r.rds.Run(q, cb) | 39 return r.rds.Run(q, cb) |
40 }) | 40 }) |
41 } | 41 } |
42 | 42 |
| 43 func (r *dsState) Count(q *ds.FinalizedQuery) (int64, error) { |
| 44 count := int64(0) |
| 45 err := r.run(func() (err error) { |
| 46 count, err = r.rds.Count(q) |
| 47 return |
| 48 }) |
| 49 return count, err |
| 50 } |
| 51 |
43 func (r *dsState) RunInTransaction(f func(c context.Context) error, opts *ds.Tra
nsactionOptions) error { | 52 func (r *dsState) RunInTransaction(f func(c context.Context) error, opts *ds.Tra
nsactionOptions) error { |
44 return r.run(func() error { | 53 return r.run(func() error { |
45 return r.rds.RunInTransaction(f, opts) | 54 return r.rds.RunInTransaction(f, opts) |
46 }) | 55 }) |
47 } | 56 } |
48 | 57 |
49 // TODO(riannucci): Allow the user to specify a multierror which will propagate | 58 // TODO(riannucci): Allow the user to specify a multierror which will propagate |
50 // to the callback correctly. | 59 // to the callback correctly. |
51 | 60 |
52 func (r *dsState) DeleteMulti(keys []*ds.Key, cb ds.DeleteMultiCB) error { | 61 func (r *dsState) DeleteMulti(keys []*ds.Key, cb ds.DeleteMultiCB) error { |
(...skipping 18 matching lines...) Expand all Loading... |
71 return r.rds.Testable() | 80 return r.rds.Testable() |
72 } | 81 } |
73 | 82 |
74 // FilterRDS installs a counter datastore filter in the context. | 83 // FilterRDS installs a counter datastore filter in the context. |
75 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB
reaker) { | 84 func FilterRDS(c context.Context, defaultError error) (context.Context, FeatureB
reaker) { |
76 state := newState(defaultError) | 85 state := newState(defaultError) |
77 return ds.AddRawFilters(c, func(ic context.Context, RawDatastore ds.RawI
nterface) ds.RawInterface { | 86 return ds.AddRawFilters(c, func(ic context.Context, RawDatastore ds.RawI
nterface) ds.RawInterface { |
78 return &dsState{state, RawDatastore} | 87 return &dsState{state, RawDatastore} |
79 }), state | 88 }), state |
80 } | 89 } |
OLD | NEW |