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 meta | 5 package meta |
6 | 6 |
7 import ( | 7 import ( |
8 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
9 | 9 |
10 "github.com/luci/luci-go/common/errors" | 10 "github.com/luci/luci-go/common/errors" |
11 | 11 |
12 "infra/gae/libs/gae" | 12 "infra/gae/libs/gae" |
13 "infra/gae/libs/gae/helper" | |
13 ) | 14 ) |
14 | 15 |
15 var mark = errors.MakeMarkFn("eg") | 16 var mark = errors.MakeMarkFn("eg") |
16 | 17 |
17 // EntityGroupMeta is the model corresponding to the __entity_group__ model in | 18 // EntityGroupMeta is the model corresponding to the __entity_group__ model in |
18 // appengine. You shouldn't need to use this struct directly, but instead should | 19 // appengine. You shouldn't need to use this struct directly, but instead should |
19 // use GetEntityGroupVersion. | 20 // use GetEntityGroupVersion. |
20 type EntityGroupMeta struct { | 21 type EntityGroupMeta struct { |
21 Version int64 `gae:"__version__"` | 22 Version int64 `gae:"__version__"` |
22 } | 23 } |
23 | 24 |
24 // GetEntityGroupVersion returns the entity group version for the entity group | 25 // GetEntityGroupVersion returns the entity group version for the entity group |
25 // containing root. If the entity group doesn't exist, this function will return | 26 // containing root. If the entity group doesn't exist, this function will return |
26 // zero and a nil error. | 27 // zero and a nil error. |
27 func GetEntityGroupVersion(c context.Context, root gae.DSKey) (int64, error) { | 28 func GetEntityGroupVersion(c context.Context, root gae.DSKey) (int64, error) { |
28 for root.Parent() != nil { | 29 for root.Parent() != nil { |
29 root = root.Parent() | 30 root = root.Parent() |
30 } | 31 } |
32 rds := gae.GetRDS(c) | |
31 egm := &EntityGroupMeta{} | 33 egm := &EntityGroupMeta{} |
32 » rds := gae.GetRDS(c) | 34 » ret := int64(0) |
dnj
2015/07/14 19:34:57
Why bother with this assignment when you can just
iannucci
2015/07/14 22:45:48
Done.
| |
33 » err := rds.Get(rds.NewKey("__entity_group__", "", 1, root), egm) | 35 » err := rds.Get(rds.NewKey("__entity_group__", "", 1, root), helper.GetPL S(egm)) |
34 » if err != gae.ErrDSNoSuchEntity { | 36 » ret = egm.Version |
35 » » err = mark(err) | 37 » if err == gae.ErrDSNoSuchEntity { |
36 » } else { | |
37 // this is OK for callers. The version of the entity group is ef fectively 0 | 38 // this is OK for callers. The version of the entity group is ef fectively 0 |
38 // in this case. | 39 // in this case. |
39 err = nil | 40 err = nil |
40 } | 41 } |
41 » return egm.Version, err | 42 » return ret, err |
42 } | 43 } |
OLD | NEW |