Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Stale children block's path-refs when parent's refs change #9254

Merged
merged 2 commits into from May 4, 2023

Conversation

logseq-cldwalker
Copy link
Collaborator

@logseq-cldwalker logseq-cldwalker commented Apr 26, 2023

This fixes a longstanding bug where a child block's :block/path-refs holds on to old path-refs when a parent's refs change. Fixes #5759, #5992, #6990, #8430 and #4116. Since this bug allowed stale refs data, this lead to stale data in query results, linked references and maybe other places. To QA, add these blocks:

- parent #foo
	- child #baz
		- grandchild #bing
- {{query (and [[foo]] <% current page %>)}}

Observe that changing #foo to #bar cleanly removes all the blocks from the query results. Another case to QA is toggle task states with children blocks as described in #5992

(let [entity (db/entity [:block/uuid id])]
{:db/id (:db/id entity)
:block/path-refs (concat
(map :db/id (:block/path-refs entity))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The bug was here as :block/path-refs had stale data

@@ -41,14 +41,36 @@
[(:db/id (:block/page block))]
(map :db/id (:block/refs block))
parents-refs))
;; Usually has changed as new-refs has page id while old-refs doesn't
refs-changed? (not= old-refs new-refs)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know if it's intentional but this was always changed when I inspected it because the old-refs didn't contain the page id

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bug because :block/path-refs is included in the retracted-attributes, the block here is from the db-after which has no path-refs already. I made the change to get the old-refs from db-before.

Copy link
Contributor

@tiensonqin tiensonqin left a comment

Choose a reason for hiding this comment

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

QAed both and this fix works great! 👍

@@ -0,0 +1,54 @@
(ns frontend.modules.outliner.pipeline-test
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@tiensonqin tiensonqin merged commit a3b60a3 into master May 4, 2023
5 of 6 checks passed
@tiensonqin tiensonqin deleted the fix/child-path-refs branch May 4, 2023 07:38
logseq-cldwalker added a commit that referenced this pull request May 4, 2023
logseq-cldwalker added a commit that referenced this pull request May 13, 2023
Looks like refs-changed? always being true in #9254 was needed for
downstream transactions. This brings back that behavior
logseq-cldwalker added a commit that referenced this pull request May 13, 2023
Looks like refs-changed? always being true in #9254 was needed for
downstream transactions. This brings back that behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

queries for tasks won't detect parent tag change until re-index
2 participants