| OLD | NEW | 
|---|
| 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 count | 5 package count | 
| 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 12 matching lines...) Expand all  Loading... | 
| 23 } | 23 } | 
| 24 | 24 | 
| 25 type dsCounter struct { | 25 type dsCounter struct { | 
| 26         c *DSCounter | 26         c *DSCounter | 
| 27 | 27 | 
| 28         ds ds.RawInterface | 28         ds ds.RawInterface | 
| 29 } | 29 } | 
| 30 | 30 | 
| 31 var _ ds.RawInterface = (*dsCounter)(nil) | 31 var _ ds.RawInterface = (*dsCounter)(nil) | 
| 32 | 32 | 
| 33 func (r *dsCounter) AllocateIDs(incomplete *ds.Key, n int) (int64, error) { | 33 func (r *dsCounter) AllocateIDs(keys []*ds.Key, cb ds.NewKeyCB) error { | 
| 34 »       start, err := r.ds.AllocateIDs(incomplete, n) | 34 »       return r.c.AllocateIDs.up(r.ds.AllocateIDs(keys, cb)) | 
| 35 »       return start, r.c.AllocateIDs.up(err) |  | 
| 36 } | 35 } | 
| 37 | 36 | 
| 38 func (r *dsCounter) DecodeCursor(s string) (ds.Cursor, error) { | 37 func (r *dsCounter) DecodeCursor(s string) (ds.Cursor, error) { | 
| 39         cursor, err := r.ds.DecodeCursor(s) | 38         cursor, err := r.ds.DecodeCursor(s) | 
| 40         return cursor, r.c.DecodeCursor.up(err) | 39         return cursor, r.c.DecodeCursor.up(err) | 
| 41 } | 40 } | 
| 42 | 41 | 
| 43 func (r *dsCounter) Run(q *ds.FinalizedQuery, cb ds.RawRunCB) error { | 42 func (r *dsCounter) Run(q *ds.FinalizedQuery, cb ds.RawRunCB) error { | 
| 44         return r.c.Run.upFilterStop(r.ds.Run(q, cb)) | 43         return r.c.Run.upFilterStop(r.ds.Run(q, cb)) | 
| 45 } | 44 } | 
| 46 | 45 | 
| 47 func (r *dsCounter) Count(q *ds.FinalizedQuery) (int64, error) { | 46 func (r *dsCounter) Count(q *ds.FinalizedQuery) (int64, error) { | 
| 48         count, err := r.ds.Count(q) | 47         count, err := r.ds.Count(q) | 
| 49         return count, r.c.Count.up(err) | 48         return count, r.c.Count.up(err) | 
| 50 } | 49 } | 
| 51 | 50 | 
| 52 func (r *dsCounter) RunInTransaction(f func(context.Context) error, opts *ds.Tra
    nsactionOptions) error { | 51 func (r *dsCounter) RunInTransaction(f func(context.Context) error, opts *ds.Tra
    nsactionOptions) error { | 
| 53         return r.c.RunInTransaction.up(r.ds.RunInTransaction(f, opts)) | 52         return r.c.RunInTransaction.up(r.ds.RunInTransaction(f, opts)) | 
| 54 } | 53 } | 
| 55 | 54 | 
| 56 func (r *dsCounter) DeleteMulti(keys []*ds.Key, cb ds.DeleteMultiCB) error { | 55 func (r *dsCounter) DeleteMulti(keys []*ds.Key, cb ds.DeleteMultiCB) error { | 
| 57         return r.c.DeleteMulti.upFilterStop(r.ds.DeleteMulti(keys, cb)) | 56         return r.c.DeleteMulti.upFilterStop(r.ds.DeleteMulti(keys, cb)) | 
| 58 } | 57 } | 
| 59 | 58 | 
| 60 func (r *dsCounter) GetMulti(keys []*ds.Key, meta ds.MultiMetaGetter, cb ds.GetM
    ultiCB) error { | 59 func (r *dsCounter) GetMulti(keys []*ds.Key, meta ds.MultiMetaGetter, cb ds.GetM
    ultiCB) error { | 
| 61         return r.c.GetMulti.upFilterStop(r.ds.GetMulti(keys, meta, cb)) | 60         return r.c.GetMulti.upFilterStop(r.ds.GetMulti(keys, meta, cb)) | 
| 62 } | 61 } | 
| 63 | 62 | 
| 64 func (r *dsCounter) PutMulti(keys []*ds.Key, vals []ds.PropertyMap, cb ds.PutMul
    tiCB) error { | 63 func (r *dsCounter) PutMulti(keys []*ds.Key, vals []ds.PropertyMap, cb ds.NewKey
    CB) error { | 
| 65         return r.c.PutMulti.upFilterStop(r.ds.PutMulti(keys, vals, cb)) | 64         return r.c.PutMulti.upFilterStop(r.ds.PutMulti(keys, vals, cb)) | 
| 66 } | 65 } | 
| 67 | 66 | 
| 68 func (r *dsCounter) Testable() ds.Testable { | 67 func (r *dsCounter) Testable() ds.Testable { | 
| 69         return r.ds.Testable() | 68         return r.ds.Testable() | 
| 70 } | 69 } | 
| 71 | 70 | 
| 72 // FilterRDS installs a counter datastore filter in the context. | 71 // FilterRDS installs a counter datastore filter in the context. | 
| 73 func FilterRDS(c context.Context) (context.Context, *DSCounter) { | 72 func FilterRDS(c context.Context) (context.Context, *DSCounter) { | 
| 74         state := &DSCounter{} | 73         state := &DSCounter{} | 
| 75         return ds.AddRawFilters(c, func(ic context.Context, ds ds.RawInterface) 
    ds.RawInterface { | 74         return ds.AddRawFilters(c, func(ic context.Context, ds ds.RawInterface) 
    ds.RawInterface { | 
| 76                 return &dsCounter{state, ds} | 75                 return &dsCounter{state, ds} | 
| 77         }), state | 76         }), state | 
| 78 } | 77 } | 
| 79 | 78 | 
| 80 // upFilterStop wraps up, handling the special case datastore.Stop error. | 79 // upFilterStop wraps up, handling the special case datastore.Stop error. | 
| 81 // datastore.Stop will pass through this function, but, unlike other error | 80 // datastore.Stop will pass through this function, but, unlike other error | 
| 82 // codes, will be counted as a success. | 81 // codes, will be counted as a success. | 
| 83 func (e *Entry) upFilterStop(err error) error { | 82 func (e *Entry) upFilterStop(err error) error { | 
| 84         upErr := err | 83         upErr := err | 
| 85         if upErr == ds.Stop { | 84         if upErr == ds.Stop { | 
| 86                 upErr = nil | 85                 upErr = nil | 
| 87         } | 86         } | 
| 88         e.up(upErr) | 87         e.up(upErr) | 
| 89         return err | 88         return err | 
| 90 } | 89 } | 
| OLD | NEW | 
|---|