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 prod | 5 package prod |
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/luci-go/common/errors" | 9 "github.com/luci/luci-go/common/errors" |
10 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
11 "google.golang.org/appengine" | 11 "google.golang.org/appengine" |
12 "google.golang.org/appengine/datastore" | 12 "google.golang.org/appengine/datastore" |
13 ) | 13 ) |
14 | 14 |
15 type dsKeyImpl struct { | 15 type dsKeyImpl struct { |
16 *datastore.Key | 16 *datastore.Key |
17 } | 17 } |
18 | 18 |
19 // dsR2F (DS real-to-fake) converts an SDK Key to a ds.Key | 19 // dsR2F (DS real-to-fake) converts an SDK Key to a ds.Key |
20 func dsR2F(k *datastore.Key) *ds.Key { | 20 func dsR2F(k *datastore.Key) *ds.Key { |
21 if k == nil { | 21 if k == nil { |
22 return nil | 22 return nil |
23 } | 23 } |
24 » aid := k.AppID() | 24 » kc := ds.KeyContext{k.AppID(), k.Namespace()} |
25 » ns := k.Namespace() | |
26 | 25 |
27 count := 0 | 26 count := 0 |
28 for nk := k; nk != nil; nk = nk.Parent() { | 27 for nk := k; nk != nil; nk = nk.Parent() { |
29 count++ | 28 count++ |
30 } | 29 } |
31 | 30 |
32 toks := make([]ds.KeyTok, count) | 31 toks := make([]ds.KeyTok, count) |
33 | 32 |
34 for ; k != nil; k = k.Parent() { | 33 for ; k != nil; k = k.Parent() { |
35 count-- | 34 count-- |
36 toks[count].Kind = k.Kind() | 35 toks[count].Kind = k.Kind() |
37 toks[count].StringID = k.StringID() | 36 toks[count].StringID = k.StringID() |
38 toks[count].IntID = k.IntID() | 37 toks[count].IntID = k.IntID() |
39 } | 38 } |
40 » return ds.NewKeyToks(aid, ns, toks) | 39 » return kc.NewKeyToks(toks) |
41 } | 40 } |
42 | 41 |
43 // dsF2R (DS fake-to-real) converts a DSKey back to an SDK *Key. | 42 // dsF2R (DS fake-to-real) converts a DSKey back to an SDK *Key. |
44 func dsF2R(aeCtx context.Context, k *ds.Key) (*datastore.Key, error) { | 43 func dsF2R(aeCtx context.Context, k *ds.Key) (*datastore.Key, error) { |
45 if k == nil { | 44 if k == nil { |
46 return nil, nil | 45 return nil, nil |
47 } | 46 } |
48 | 47 |
49 // drop aid. | 48 // drop aid. |
50 _, ns, toks := k.Split() | 49 _, ns, toks := k.Split() |
(...skipping 15 matching lines...) Expand all Loading... |
66 func dsMF2R(aeCtx context.Context, ks []*ds.Key) ([]*datastore.Key, error) { | 65 func dsMF2R(aeCtx context.Context, ks []*ds.Key) ([]*datastore.Key, error) { |
67 lme := errors.NewLazyMultiError(len(ks)) | 66 lme := errors.NewLazyMultiError(len(ks)) |
68 ret := make([]*datastore.Key, len(ks)) | 67 ret := make([]*datastore.Key, len(ks)) |
69 err := error(nil) | 68 err := error(nil) |
70 for i, k := range ks { | 69 for i, k := range ks { |
71 ret[i], err = dsF2R(aeCtx, k) | 70 ret[i], err = dsF2R(aeCtx, k) |
72 lme.Assign(i, err) | 71 lme.Assign(i, err) |
73 } | 72 } |
74 return ret, lme.Get() | 73 return ret, lme.Get() |
75 } | 74 } |
OLD | NEW |