Skip to content

fix(memopayload): collect memo IDs in one query so none is skipped - #6666

Merged
boojack merged 2 commits into
usememos:mainfrom
ashokram-si:fix/memopayload-list-ids-once
Nov 27, 2026
Merged

boojack merged 2 commits into
usememos:mainfrom
ashokram-si:fix/memopayload-list-ids-once

Conversation

@ashokram-si

Copy link
Copy Markdown
Contributor

Fixes #6664

Root cause

listMemoIDs read the memo IDs page by page (LIMIT/OFFSET, ordered by created time) while the server takes writes. A memo deleted, or one whose created time was changed, between two page reads moved the rows after it to another page, so one memo was never rebuilt, and the pass still recorded the new Version.

Changes

  • core/memopayload/runner.go: listMemoIDs reads every memo ID in one ListMemos query (ExcludeContent, same order). RunOnce still loads and rebuilds the memos in batches of 100. The comments on RunOnce and listMemoIDs say why.
  • core/memopayload/runner_test.go: TestRunOnceRebuildsEveryMemoWhenOneIsDeletedDuringThePass wraps the store driver, as store/test/reaction_test.go does, and deletes the first memo right after the first list of IDs is read. With 150 memos it fails on main (one memo keeps its stale payload) and passes with the fix.
  • docs/design/memo-attachment-filters.md: a dated amendment, since its Coverage paragraph said the paged read could not skip a memo.

Notes

  • None of the three drivers adds a default LIMIT or filter, so the single query returns the same memos as before on SQLite, MySQL and PostgreSQL.
  • The query holds each memo without its content (payload included) until the IDs are copied out, roughly a few hundred bytes per memo, once per Version bump. A SELECT id driver method or ID-based paging would hold less; both change the Driver interface and all three drivers, so I left that out. Happy to add it if you prefer.

Verification

  • go test -race ./server/... ./core/...: pass.
  • golangci-lint run (v2.14.0): no issues in core/; go fix -diff: clean.

@ashokram-si
ashokram-si requested a review from a team as a code owner November 27, 2026 08:36
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The runner now collects memo IDs with one query instead of paginating with LIMIT and OFFSET. It continues to rebuild memos in batches of 100. A new test deletes one memo after the ID listing and checks that the other 149 memos receive rebuilt tags. The design document records the change to ID collection.

Suggested reviewers: johnnyjoygh, boojack

Severity of issue fixed: Medium

Merge Risk: Minimal · up to e3361

This change makes the payload rebuild reliably process every remaining memo even when memos are deleted or re-dated during the pass. It is covered by new tests, and I found no merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (collecting memo IDs in one query so none is skipped) and the affected package (memopayload). This matches the main change in runner.go, which replaces paginated listMemoIDs wi…
Description check Passed The description states the root cause (paged LIMIT/OFFSET reads skipping memos during writes), lists the changes to runner.go, runner_test.go, and the design doc, and gives notes and verification step…
Linked Issues check Passed Issue #6664 requires that a rebuild after a memopayload.Version increase rebuilds every memo that exists after the pass, even when a memo is deleted or re-dated during ID collection. At the reviewed h…
Out of Scope Changes check Passed The changes connect to #6664. core/memopayload/runner.go replaces the paged read with one ID query and updates the RunOnce comments. store/driver.go, store/memo.go and the three driver packages add Li…
Full details: Title check

Explanation

The title names the fix (collecting memo IDs in one query so none is skipped) and the affected package (memopayload). This matches the main change in runner.go, which replaces paginated listMemoIDs with a single ListMemoIDs call, and the linked issue about skipped memos.

Full details: Description check

Explanation

The description states the root cause (paged LIMIT/OFFSET reads skipping memos during writes), lists the changes to runner.go, runner_test.go, and the design doc, and gives notes and verification steps. It relates directly to the changeset.

Full details: Linked Issues check

Explanation

Issue #6664 requires that a rebuild after a memopayload.Version increase rebuilds every memo that exists after the pass, even when a memo is deleted or re-dated during ID collection. At the reviewed head, core/memopayload/runner.go RunOnce calls Store.ListMemoIDs once, before any batch read. The head file shows this with no LIMIT/OFFSET paging. RunOnce then loads memos in batches of 100 through ListMemos with IDList. A delete or created-time change after the ID read cannot move unread IDs out of the list. The head code therefore meets the paging requirement. The ID query is a new Driver method, implemented in store/db/sqlite, mysql and postgres memo.go (read from the whole-PR diff for sqlite; the mysql and postgres files and store/test/memo_test.go were described in the change summary but not read directly). The test TestRunOnceRebuildsEveryMemoWhenOneIsDeletedDuringThePass in core/memopayload/runner_test.go was read at head. It wraps the driver, deletes the first ID after listing, and asserts that the remaining 149 memos have rebuilt tags. The test was not re-run. Uncertainty: the batch ListMemos(IDList) path was not checked for driver-level default filters, so archived or comment memos in the ID list are assumed to load. The test covers only normal memos.

Full details: Out of Scope Changes check

Explanation

The changes connect to #6664. core/memopayload/runner.go replaces the paged read with one ID query and updates the RunOnce comments. store/driver.go, store/memo.go and the three driver packages add ListMemoIDs, which the fixed RunOnce needs. store/test/memo_test.go tests the new query. core/memopayload/runner_test.go adds the regression test. docs/design/memo-attachment-filters.md gets a dated amendment for the paged-read claim this change corrects. No unrelated change was found. Mismatch to note: the PR description and objectives say the change uses one ListMemos query with ExcludeContent and avoids Driver interface changes. The reviewed head instead adds a Driver method ListMemoIDs. That is a description mismatch, not an out-of-scope change. The description should be updated.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4e6bf079-4235-4891-90c6-bde2df0223ac
Commits

Reviewing files that changed from the base of the PR and between 0c9d7e5 and e336177.

Files selected for processing: 9

  • core/memopayload/runner.go
  • core/memopayload/runner_test.go
  • docs/design/memo-attachment-filters.md
  • store/db/mysql/memo.go
  • store/db/postgres/memo.go
  • store/db/sqlite/memo.go
  • store/driver.go
  • store/memo.go
  • store/test/memo_test.go
Files skipped from review as they are similar to previous changes: 1

  • docs/design/memo-attachment-filters.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Listing every memo without a limit to collect the IDs held each memo's
payload in memory for the length of the read. Add store.ListMemoIDs,
which selects only the id column in ID order on all three drivers, and
have the rebuild use it.

The runner test now deletes a memo right after the IDs are read, so it
fails if the pass stops going through the single ID query.
@boojack
boojack merged commit 78a8dc8 into usememos:main Nov 27, 2026
12 checks passed
@ashokram-si
ashokram-si deleted the fix/memopayload-list-ids-once branch November 28, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Payload rebuild on upgrade can skip a memo when memos change during the pass

2 participants