fix(search): reindex holders after property delete by tiensonqin · Pull Request #13173 · logseq/logseq · GitHub
Skip to content

fix(search): reindex holders after property delete - #13173

Open
tiensonqin wants to merge 2 commits into
masterfrom
logseq/fix-property-delete-fts-holders-a7e8
Open

fix(search): reindex holders after property delete#13173
tiensonqin wants to merge 2 commits into
masterfrom
logseq/fix-property-delete-fts-holders-a7e8

Conversation

@tiensonqin

@tiensonqin tiensonqin commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Fixes logseq/db-test#1153 (transferred from logseq/logseq#13170).

Problem

On a DB graph, deleting a property removed every page/block that held that property from the FTS search index. Datascript still had the entities; only the worker blocks / blocks_fts rows were deleted. Rebuild search index (or editing a title) was required to bring them back.

Cause

frontend.worker.search/get-blocks-from-datoms-impl put holders into remove-eids via referrer-eids on db-before (they :block/refs the property). After the property eid is gone, referrer-eids on db-after is empty, and the holders' own titles did not change, so they never reached add-eids. The listener then deleted their FTS rows and upserted nothing.

Change

Include db-before referrers on the add side. Surviving holders are reindexed; entities that no longer exist in db-after are still dropped by entities-for / block->index, and sync-search-indice keeps those in the remove set.

Tests

frontend.worker.search-test/sync-search-indice-reindexes-holders-when-property-is-deleted deletes a user property through outliner-page/build-page-retract-tx and asserts:

  • holder page and block remain in Datascript
  • both are in :blocks-to-add (FTS reindex)
  • both are also in :blocks-to-remove-set (delete-then-upsert)
  • the deleted property is in :blocks-to-remove-set and is not re-added

The test seeds :block/refs from holders to the property, matching the worker refs pipeline that production uses when a property value is set.

Verified: LOGSEQ_STABLE_IDENTS=1 node static/tests.js -n frontend.worker.search-test — 59 tests, 195 assertions, 0 failures.

Open in Web Open in Cursor 

Deleting a property put its still-alive holder pages/blocks in the FTS
remove set via db-before referrers, but not in the add set once the
property eid was gone. Reindex surviving referrers from db-before so
holders stay findable.

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
Copilot AI lite review requested due to automatic review settings September 5, 2026 16:45
create-conn-with-blocks does not run the worker refs pipeline, so the
regression test now adds the same :block/refs links production uses.

Co-authored-by: Tienson Qin <tiensonqin@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrow, aligns with the described failure mode, and includes a focused regression test that would fail under the prior behavior.

Pull request overview

This PR fixes a DB-graph search indexing regression where deleting a property could remove all pages/blocks that held that property from the FTS index (even though those entities still existed in DataScript), requiring a full reindex or manual edits to restore searchability.

Changes:

  • Update frontend.worker.search/get-blocks-from-datoms-impl so referrers from db-before are also included in the “add” side, ensuring surviving holders get reindexed after the referenced entity (property) is deleted.
  • Add a targeted CLJS unit test covering property deletion via outliner-page/build-page-retract-tx and asserting holders are re-added while the deleted property stays removed from the index.
File summaries
File Description
src/main/frontend/worker/search.cljs Ensures referrers from db-before are included in add-eids so holders of a deleted property are reindexed.
src/test/frontend/worker/search_test.cljs Adds regression test asserting holders remain in DataScript and are reindexed after property deletion.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

DB graph: deleting a property removes every page/block that held it from the search index (never re-added)

3 participants