Improve optimizations
This commit is contained in:
parent
82b25bd2a6
commit
d98816212d
2 changed files with 14 additions and 6 deletions
|
@ -137,15 +137,13 @@ export class Tag extends TagsFilter {
|
||||||
* new Tag("key","value").shadows(new And([new Tag("x","y"), new RegexTag("a","b", true)]) // => false
|
* new Tag("key","value").shadows(new And([new Tag("x","y"), new RegexTag("a","b", true)]) // => false
|
||||||
*/
|
*/
|
||||||
shadows(other: TagsFilter): boolean {
|
shadows(other: TagsFilter): boolean {
|
||||||
if (other["key"] !== this.key) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if (other instanceof Tag) {
|
if (other instanceof Tag) {
|
||||||
// Other.key === this.key
|
return other.key === this.key && other.value === this.value
|
||||||
return other.value === this.value
|
|
||||||
}
|
}
|
||||||
if (other instanceof RegexTag) {
|
if (other instanceof RegexTag) {
|
||||||
return other.matchesProperties({ [this.key]: this.value })
|
if(other.key === this.key || !other.invert){
|
||||||
|
return other.matchesProperties({ [this.key]: this.value })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,6 +181,16 @@ describe("Tag optimalization", () => {
|
||||||
const q = new And([new Tag("key", "value"), new RegexTag("key", /value/, true)])
|
const q = new And([new Tag("key", "value"), new RegexTag("key", /value/, true)])
|
||||||
expect(q.optimize()).toBe(false)
|
expect(q.optimize()).toBe(false)
|
||||||
})
|
})
|
||||||
|
it("should optimize regexes in the key", () => {
|
||||||
|
const spec = TagUtils.Tag({
|
||||||
|
and: [
|
||||||
|
"service:bicycle:retail=yes",
|
||||||
|
"service:bicycle:.+~~yes"
|
||||||
|
]
|
||||||
|
})
|
||||||
|
const tag = <TagsFilter> spec.optimize()
|
||||||
|
expect(tag.asJson()).to.eq("service:bicycle:retail=yes")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("Or", () => {
|
describe("Or", () => {
|
||||||
|
|
Loading…
Reference in a new issue