Chromium Code Reviews| 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 memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "sort" | 10 "sort" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 } | 37 } |
| 38 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I ndexColumn{{Property: name}}}) | 38 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I ndexColumn{{Property: name}}}) |
| 39 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I ndexColumn{{Property: name, Descending: true}}}) | 39 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I ndexColumn{{Property: name, Descending: true}}}) |
| 40 } | 40 } |
| 41 if serializationDeterministic { | 41 if serializationDeterministic { |
| 42 sort.Sort(ret) | 42 sort.Sort(ret) |
| 43 } | 43 } |
| 44 return ret | 44 return ret |
| 45 } | 45 } |
| 46 | 46 |
| 47 // indexEntriesWithBuiltins generates a new memStore containing the default | |
| 48 // indexes for (k, pm) combined with complexIdxs. | |
| 49 // | |
| 50 // If "pm" is nil, this indicates an absence of a value. This is used | |
| 51 // specifically deletion. | |
|
iannucci
2016/11/12 00:19:12
typo?
| |
| 47 func indexEntriesWithBuiltins(k *ds.Key, pm ds.PropertyMap, complexIdxs []*ds.In dexDefinition) memStore { | 52 func indexEntriesWithBuiltins(k *ds.Key, pm ds.PropertyMap, complexIdxs []*ds.In dexDefinition) memStore { |
| 48 » sip := serialize.PropertyMapPartially(k, pm) | 53 » var sip serialize.SerializedPmap |
| 54 » if pm == nil { | |
| 55 » » return newMemStore() | |
| 56 » } | |
| 57 » sip = serialize.PropertyMapPartially(k, pm) | |
| 49 return indexEntries(sip, k.Namespace(), append(defaultIndexes(k.Kind(), pm), complexIdxs...)) | 58 return indexEntries(sip, k.Namespace(), append(defaultIndexes(k.Kind(), pm), complexIdxs...)) |
| 50 } | 59 } |
| 51 | 60 |
| 52 // indexRowGen contains enough information to generate all of the index rows whi ch | 61 // indexRowGen contains enough information to generate all of the index rows whi ch |
| 53 // correspond with a propertyList and a ds.IndexDefinition. | 62 // correspond with a propertyList and a ds.IndexDefinition. |
| 54 type indexRowGen struct { | 63 type indexRowGen struct { |
| 55 propVec []serialize.SerializedPslice | 64 propVec []serialize.SerializedPslice |
| 56 decending []bool | 65 decending []bool |
| 57 } | 66 } |
| 58 | 67 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 if pv, ok := sip[sb.Property]; ok { | 135 if pv, ok := sip[sb.Property]; ok { |
| 127 m.buf.propVec = append(m.buf.propVec, pv) | 136 m.buf.propVec = append(m.buf.propVec, pv) |
| 128 m.buf.decending = append(m.buf.decending, sb.Descending) | 137 m.buf.decending = append(m.buf.decending, sb.Descending) |
| 129 } else { | 138 } else { |
| 130 return indexRowGen{}, false | 139 return indexRowGen{}, false |
| 131 } | 140 } |
| 132 } | 141 } |
| 133 return m.buf, true | 142 return m.buf, true |
| 134 } | 143 } |
| 135 | 144 |
| 145 // indexEntries generates a new memStore containing the specified index | |
| 146 // definitions. | |
| 136 func indexEntries(sip serialize.SerializedPmap, ns string, idxs []*ds.IndexDefin ition) memStore { | 147 func indexEntries(sip serialize.SerializedPmap, ns string, idxs []*ds.IndexDefin ition) memStore { |
| 137 ret := newMemStore() | 148 ret := newMemStore() |
| 138 idxColl := ret.GetOrCreateCollection("idx") | 149 idxColl := ret.GetOrCreateCollection("idx") |
| 139 | 150 |
| 140 mtch := matcher{} | 151 mtch := matcher{} |
| 141 for _, idx := range idxs { | 152 for _, idx := range idxs { |
| 142 idx = idx.Normalize() | 153 idx = idx.Normalize() |
| 143 if irg, ok := mtch.match(idx.GetFullSortOrder(), sip); ok { | 154 if irg, ok := mtch.match(idx.GetFullSortOrder(), sip); ok { |
| 144 idxBin := serialize.ToBytes(*idx.PrepForIdxTable()) | 155 idxBin := serialize.ToBytes(*idx.PrepForIdxTable()) |
| 145 idxColl.Set(idxBin, []byte{}) | 156 idxColl.Set(idxBin, []byte{}) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 | 260 |
| 250 mergeIndexes(ns, store, | 261 mergeIndexes(ns, store, |
| 251 newMemStore(), | 262 newMemStore(), |
| 252 indexEntries(sip, ns, normalized)) | 263 indexEntries(sip, ns, normalized)) |
| 253 return true | 264 return true |
| 254 }) | 265 }) |
| 255 } | 266 } |
| 256 } | 267 } |
| 257 } | 268 } |
| 258 | 269 |
| 270 // updateIndexes updates the indexes in store to accommodate a change in entity | |
| 271 // value. | |
| 272 // | |
| 273 // oldEnt is the previous entity value, and newEnt is the new entity value. If | |
| 274 // newEnt is nil, that signifies deletion. | |
| 259 func updateIndexes(store memStore, key *ds.Key, oldEnt, newEnt ds.PropertyMap) { | 275 func updateIndexes(store memStore, key *ds.Key, oldEnt, newEnt ds.PropertyMap) { |
| 260 // load all current complex query index definitions. | 276 // load all current complex query index definitions. |
| 261 » compIdx := []*ds.IndexDefinition{} | 277 » var compIdx []*ds.IndexDefinition |
| 262 walkCompIdxs(store.Snapshot(), nil, func(i *ds.IndexDefinition) bool { | 278 walkCompIdxs(store.Snapshot(), nil, func(i *ds.IndexDefinition) bool { |
| 263 compIdx = append(compIdx, i) | 279 compIdx = append(compIdx, i) |
| 264 return true | 280 return true |
| 265 }) | 281 }) |
| 266 | 282 |
| 267 mergeIndexes(key.Namespace(), store, | 283 mergeIndexes(key.Namespace(), store, |
| 268 indexEntriesWithBuiltins(key, oldEnt, compIdx), | 284 indexEntriesWithBuiltins(key, oldEnt, compIdx), |
| 269 indexEntriesWithBuiltins(key, newEnt, compIdx)) | 285 indexEntriesWithBuiltins(key, newEnt, compIdx)) |
| 270 } | 286 } |
| OLD | NEW |