@@ -149,7 +149,9 @@ func (c *FindCache) InvalidateFor(orgId uint32, path string) {
149
149
}
150
150
151
151
// convert our path to a tree so that we can call `find(tree, pattern)`
152
- // for each pattern in the cache.
152
+ // for each pattern in the cache and purge it if it matches the path or a subtree of it.
153
+ // we can't simply prune all cache keys that equal path or a subtree of it, because
154
+ // what's cached are search patterns which may contain wildcards and other expressions
153
155
tree := treeFromPath (path )
154
156
155
157
for _ , k := range cache .Keys () {
@@ -181,29 +183,23 @@ func (p *PartitionedMemoryIdx) PurgeFindCache() {
181
183
}
182
184
}
183
185
184
- // treeFromPath creates a index tree from a series path.
186
+ // treeFromPath creates an index tree from a series path.
185
187
// The tree will have a single leaf node and nodes for
186
188
// each branch.
187
189
func treeFromPath (path string ) * Tree {
188
- tree := & Tree {
190
+ tree := Tree {
189
191
Items : map [string ]* Node {
190
- "" : {
191
- Path : "" ,
192
- Children : make ([]string , 0 ),
193
- Defs : make ([]schema.MKey , 0 ),
194
- },
192
+ "" : {},
195
193
},
196
194
}
197
195
pos := strings .Index (path , "." )
198
- prevPos := 0
196
+ var parentBranch string
197
+ prevPos := - 1
199
198
for {
200
199
branch := path [:pos ]
201
- // add as child of parent branch
202
200
thisNode := branch [prevPos + 1 :]
203
- if prevPos == 0 {
204
- thisNode = branch [prevPos :]
205
- }
206
- tree .Items [path [:prevPos ]].Children = []string {thisNode }
201
+
202
+ tree .Items [parentBranch ].Children = []string {thisNode }
207
203
208
204
// create this branch/leaf
209
205
tree .Items [branch ] = & Node {
@@ -220,7 +216,8 @@ func treeFromPath(path string) *Tree {
220
216
} else {
221
217
pos = pos + nextPos + 1
222
218
}
219
+ parentBranch = branch
223
220
}
224
221
225
- return tree
222
+ return & tree
226
223
}
0 commit comments