mirror of
https://github.com/usememos/memos.git
synced 2025-12-27 19:19:16 +08:00
- Updated memo and reaction filtering logic to use a unified engine for compiling filter expressions into SQL statements. - Removed redundant filter parsing and conversion code from ListMemoRelations, ListReactions, and ListAttachments methods. - Introduced IDList and UIDList fields in FindMemo and FindReaction structs to support filtering by multiple IDs. - Removed old filter test files for reactions and attachments, as the filtering logic has been centralized. - Updated tests for memo filtering to reflect the new SQL statement compilation approach. - Ensured that unsupported user filters return an error in ListUsers method.
2.2 KiB
2.2 KiB
Maintaining the Memo Filter Engine
The engine is memo-specific; any future field or behavior changes must stay consistent with the memo schema and store implementations. Use this guide when extending or debugging the package.
Adding a New Memo Field
- Update the schema
- Add the field entry in
schema.go. - Define the backing column (
Column), JSON path (if applicable), type, and allowed operators. - Include the CEL variable in
EnvOptions.
- Add the field entry in
- Adjust parser or renderer (if needed)
- For non-scalar fields (JSON booleans, lists), add handling in
parser.goor extend the renderer helpers. - Keep validation in the parser (e.g., reject unsupported operators).
- For non-scalar fields (JSON booleans, lists), add handling in
- Write a golden test
- Extend the dialect-specific memo filter tests under
store/db/{sqlite,mysql,postgres}/memo_filter_test.gowith a case that exercises the new field.
- Extend the dialect-specific memo filter tests under
- Run
go test ./...to ensure the SQL output matches expectations across all dialects.
Supporting Dialect Nuances
- Centralize differences inside
render.go. If a new dialect-specific behavior emerges (e.g., JSON operators), add the logic there rather than leaking it into store code. - Use the renderer helpers (
jsonExtractExpr,jsonArrayExpr, etc.) rather than sprinkling ad-hoc SQL strings. - When placeholders change, adjust
addArgso that argument numbering stays in sync with store queries.
Debugging Tips
- Parser errors – Most originate in
buildConditionor schema validation. Enable logging aroundparser.gowhen diagnosing unknown identifier/operator messages. - Renderer output – Temporary printf/log statements in
renderConditionhelp identify which IR node produced unexpected SQL. - Store integration – Ensure drivers call
filter.DefaultEngine()exactly once per process; the singleton caches the parsed CEL environment.
Testing Checklist
go test ./store/...ensures all dialect tests consume the engine correctly.- Add targeted unit tests whenever new IR nodes or renderer paths are introduced.
- When changing boolean or JSON handling, verify all three dialect test suites (SQLite, MySQL, Postgres) to avoid regression.