Repository navigation
fix: restore case-insensitive contains/not contains/not in and consolidate metadata filter pipeline - #15686
Conversation
This change eliminates the duplicate filtering implementation between service.ApplyMetaFilter and common.MetaFilter by removing the applySingleCondition adapter layer and consolidating all operator handling into common.MetaFilter. Key changes: - Remove applySingleCondition (65 lines of inline switch logic) - ApplyMetaFilter now converts MetaFilterCondition to MetaCondition and delegates directly to common.MetaFilter once per filter set - Add filterSet: O(n+m) hash-map fast path for in/not in operators (replaces O(n*m) linear scan in matchValue) - Export NormalizeOperator from common for operator alias mapping (includes ==, !=, >=, <=, is, not is aliases) Bug fixes: - contains/not contains: restored case-insensitive matching (ToLower) - not in: restored case-insensitive matching (EqualFold) - != with date filter: non-date metadata values now correctly match the != operator (they are not equal to the date) - Added == to operatorMapping so both ParseAndConvert and convertToMetaCondition normalize it to = Performance: - in/not in: O(n*m) linear scan -> O(n+m) hash-map lookup via filterSet - = operator delegates to common.MetaFilter (O(n) iteration for correctness/case-insensitivity, matching Python behavior) Cleanup: - Removed 18 lines of dead code (matchValue's in/not in branches bypassed by filterOut delegation) - Fixed orphaned godoc comment for convertOperator (reordered with NormalizeOperator) - Fixed filterSet doc comment: removed incorrect 'matching EqualFold' claim - Completed convertToMetaCondition operator normalization comment Tests: 60 tests (24 service + 36 common), all passing. New tests cover ==, !=, >=, <=, >, <, empty, not empty operators through ApplyMetaFilter; <, <=, !=, not-in-empty-list through MetaFilter/filterSet. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR refactors metadata filtering by introducing operator alias normalization ( ChangesMetadata Filtering Enhancement
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/service/metadata_filter.go`:
- Around line 240-249: The code that handles the "in"/"not in" branch splits
f.Value into parts and appends trimmed parts to arr but does not filter out
empty or whitespace-only entries, causing "" to be included in mc.Value; update
the loop over parts (the slice named parts derived from f.Value) to TrimSpace
each p and skip any that result in an empty string (i.e., continue when trimmed
== "") before appending to arr so mc.Value contains only non-empty values.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bebfb38f-7687-4412-9d84-7b38ffaccd19
📒 Files selected for processing (5)
internal/common/metadata_utils.gointernal/common/metadata_utils_test.gointernal/dao/task_test.gointernal/service/metadata_filter.gointernal/service/metadata_filter_test.go
💤 Files with no reviewable changes (1)
- internal/dao/task_test.go
This file was accidentally included in the previous commit via git add internal/. The change was pre-existing in the working tree but unrelated to the metadata filter refactoring. Co-Authored-By: Claude Opus 4.8 <[email protected]>
When f.Value is "A,,B" or "A, ,B", strings.Split produces empty or whitespace-only entries. These are now filtered out after TrimSpace to prevent unintended matches against empty-string metadata values. Add 5 test cases: - InEmptyParts: A,,B produces [A B] - InOnlyWhitespaceParts: A, , ,B produces [A B] - InAllEmptyParts: ,,, produces [] - NotInEmptyParts: A,,B produces [A B] - InMixedSpaces: spaces around values preserve trimmed values Co-Authored-By: Claude Opus 4.8 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15686 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
This PR fixes case-sensitivity regressions introduced in #15656 and consolidates the metadata filtering pipeline by removing the duplicate
applySingleConditionadapter layer.Bug fixes
applySingleConditionwas replaced bycommon.MetaFilter.matchValuewhich lackedstrings.ToLower)strings.EqualFold)≠operator (a non-date value IS not equal to any date, but was returning false)Architecture
applySingleCondition(65 lines) — the inline switch was a duplicate ofcommon.MetaFilterlogic.ApplyMetaFilternow converts conditions and delegates tocommon.MetaFilteronce per filter set, eliminating ~25 lines of duplicate AND/OR merge logic.filterSet— O(n+m) hash-map fast path forin/not inoperators, replacing the O(n*m) linear scan inmatchValue.NormalizeOperatorfromcommonfor consistent operator alias handling.Cleanup
matchValue'sin/not inbranches already bypassed byfilterOutdelegation)convertOperatorfilterSetdoc comment (claimed "matching EqualFold" but usedstrings.ToLower)convertToMetaConditionoperator normalization documentationTesting
==,≠,>,<,≥,≤,empty,not emptythroughApplyMetaFilter<,≤,≠throughMetaFilter;not-in-empty-listthroughfilterSetMetaFiltertests pass; all 10filterSetunit tests pass