blacksmithgu / datacore

Work-in-progress successor to Dataview with a focus on UX and speed.
MIT License
1.5k stars 16 forks source link

Fix links from a markdown block not properly unindexed #31

Closed RyotaUshio closed 1 year ago

RyotaUshio commented 1 year ago

Steps to reproduce

  1. Create two notes "Source.md" and "Target.md". At this point, datacore.core.datastore.links.get('Target.md') (the backlinks to Target.md) is of course empty.
image
  1. In Source.md, insert a link to Target.md. At this point, the backlinks are properly populated by three objects: the note Source.md (MarkdownPage), it first section (MarkdownSection), and the first block in this section (MarkdownBlock).
image
  1. Remove the link from Source.md to Targe.md. Now the problem occurs: two of the three objects are properly removed by _unindex method of Datastore, but Source.md/block1 is not. It should get back to an empty set.
image

Cause

This bug is caused by this line in Datastore.prototype._unindex, I think: https://github.com/blacksmithgu/datacore/blob/5fdeb17522770fa75b6a4083c6d850e83c13a6b9/src/index/datastore.ts#L215

MarkdownPage and MarkdownSection are linkable, so they can be properly unindexed. However, MarkdownBlock is not linkable. This is why the unindexing was skipped for Source.md/block1.

Solution

I think LINKABLE_TYPE in the first condition should instead be LINKBEARING_TYPE because we need $links here, not $link.

Result

After this modification, everything looks fine:

1.

image

2.

image

3.

image
blacksmithgu commented 1 year ago

Great fixes!