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

Side by Side Diff: filter/dscache/support.go

Issue 1292913002: Split off serialization and key functions to their own packages. (Closed) Base URL: https://github.com/luci/gae.git@make_queries_better
Patch Set: rebase Created 5 years, 4 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 | « filter/dscache/serialize.go ('k') | impl/dummy/dummy.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 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 dscache 5 package dscache
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "math/rand" 9 "math/rand"
10 "time" 10 "time"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ret = make([]string, len(keys)) 53 ret = make([]string, len(keys))
54 } 54 }
55 ret[i] = MakeMemcacheKey(s.mr.Intn(shards), key) 55 ret[i] = MakeMemcacheKey(s.mr.Intn(shards), key)
56 } 56 }
57 return ret 57 return ret
58 } 58 }
59 59
60 func (s *supportContext) mkAllKeys(keys []ds.Key) []string { 60 func (s *supportContext) mkAllKeys(keys []ds.Key) []string {
61 size := 0 61 size := 0
62 nums := make([]int, len(keys)) 62 nums := make([]int, len(keys))
63 » for i, k := range keys { 63 » for i, key := range keys {
64 » » if !ds.KeyIncomplete(k) { 64 » » if !key.Incomplete() {
65 » » » shards := s.numShards(k) 65 » » » shards := s.numShards(key)
66 nums[i] = shards 66 nums[i] = shards
67 size += shards 67 size += shards
68 } 68 }
69 } 69 }
70 if size == 0 { 70 if size == 0 {
71 return nil 71 return nil
72 } 72 }
73 ret := make([]string, 0, size) 73 ret := make([]string, 0, size)
74 for i, key := range keys { 74 for i, key := range keys {
75 » » if !ds.KeyIncomplete(key) { 75 » » if !key.Incomplete() {
76 keySuffix := HashKey(key) 76 keySuffix := HashKey(key)
77 for shard := 0; shard < nums[i]; shard++ { 77 for shard := 0; shard < nums[i]; shard++ {
78 ret = append(ret, fmt.Sprintf(KeyFormat, shard, keySuffix)) 78 ret = append(ret, fmt.Sprintf(KeyFormat, shard, keySuffix))
79 } 79 }
80 } 80 }
81 } 81 }
82 return ret 82 return ret
83 } 83 }
84 84
85 // crappyNonce creates a really crappy nonce using math/rand. This is generally 85 // crappyNonce creates a really crappy nonce using math/rand. This is generally
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return nil, nil 149 return nil, nil
150 } 150 }
151 ret := make([]memcache.Item, len(mcKeys)) 151 ret := make([]memcache.Item, len(mcKeys))
152 for i := range ret { 152 for i := range ret {
153 ret[i] = (s.mc.NewItem(mcKeys[i]). 153 ret[i] = (s.mc.NewItem(mcKeys[i]).
154 SetFlags(uint32(ItemHasLock)). 154 SetFlags(uint32(ItemHasLock)).
155 SetExpiration(time.Second * time.Duration(LockTimeSecond s))) 155 SetExpiration(time.Second * time.Duration(LockTimeSecond s)))
156 } 156 }
157 return ret, mcKeys 157 return ret, mcKeys
158 } 158 }
OLDNEW
« no previous file with comments | « filter/dscache/serialize.go ('k') | impl/dummy/dummy.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698