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

Side by Side Diff: impl/prod/datastore_key.go

Issue 2353063004: Add "MkKeyContext" KeyContext generation function. (Closed)
Patch Set: 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 | « impl/memory/testing_utils_test.go ('k') | impl/prod/raw_datastore_type_converter.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 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 » kc := ds.KeyContext{k.AppID(), k.Namespace()} 24 » kc := ds.MkKeyContext(k.AppID(), k.Namespace())
25 25
26 count := 0 26 count := 0
27 for nk := k; nk != nil; nk = nk.Parent() { 27 for nk := k; nk != nil; nk = nk.Parent() {
28 count++ 28 count++
29 } 29 }
30 30
31 toks := make([]ds.KeyTok, count) 31 toks := make([]ds.KeyTok, count)
32 32
33 for ; k != nil; k = k.Parent() { 33 for ; k != nil; k = k.Parent() {
34 count-- 34 count--
(...skipping 30 matching lines...) Expand all
65 func dsMF2R(aeCtx context.Context, ks []*ds.Key) ([]*datastore.Key, error) { 65 func dsMF2R(aeCtx context.Context, ks []*ds.Key) ([]*datastore.Key, error) {
66 lme := errors.NewLazyMultiError(len(ks)) 66 lme := errors.NewLazyMultiError(len(ks))
67 ret := make([]*datastore.Key, len(ks)) 67 ret := make([]*datastore.Key, len(ks))
68 err := error(nil) 68 err := error(nil)
69 for i, k := range ks { 69 for i, k := range ks {
70 ret[i], err = dsF2R(aeCtx, k) 70 ret[i], err = dsF2R(aeCtx, k)
71 lme.Assign(i, err) 71 lme.Assign(i, err)
72 } 72 }
73 return ret, lme.Get() 73 return ret, lme.Get()
74 } 74 }
OLDNEW
« no previous file with comments | « impl/memory/testing_utils_test.go ('k') | impl/prod/raw_datastore_type_converter.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698