getmatterapp / obsidian-matter

The Matter Obsidian plugin
GNU General Public License v3.0
124 stars 11 forks source link

Duplicate Notes #52

Open thorms11 opened 1 year ago

thorms11 commented 1 year ago

This bug was fixed, but seems to be back.

See screenshots: https://share.icloud.com/photos/08cF_RV0KJ9Syrf8r3UhVtcMg

I do not have recreate note on.

ryanjm commented 1 year ago

I have "Always create missing files" enabled, but all the notes where there. I had edited them, adding additional tags and notes, but I left the title the same. I'm seeing "{file name} 2" now for each file.

I guess I'll turn off Always create missing files for now, but it seems like if the file name already exists, it shouldn't try to recreate the file.

Though this makes me wonder how it handles the edge case of additional highlights/notes being added in Matter. Does it overwrite the file, merge the two, or just append new highlights?

ejolly commented 6 months ago

@thorms11 @ryanjm I'm also experiencing this issue and it's getting worse. Some of my older matter syncs have been duplicated multiple times (e.g. 2, 3 appended to file title). If delete them all and start again any of the files that had duplicates previously, get synced with the largest duplicate number, i.e. a file duplicated 3 times on a fresh sync would be named Title-3.md

BUT I believe I found the cause and a solution in case it's helpful:

Within your vault if you check out .obsidian/plugins/matter/data.json you'll see a field called 'contentMap' that has a mapping between file names and what I assume are item id's in Matter's database for your user account.

I noticed that some of these file names were the duplicates (i.e. ended in 2 or 3) but not the originals. I'm also using Obsidian sync between an iOS device and a macOS device and noticed that duplicates were more likely when I had not switched between devices in a while. At the same time I've had sync on startup enabled in the Matter plugin on both devices.

For me, I think this created a kind of "race condition" between Obsidian sync and Matter sync, which itself depends on a file managed by Obsidian sync (data.json). When launching Obsidian on a device for the first time in a while, these competed and sometimes the freshest data.json would be pulled to the device after the matter sync had just completed which ran using the old version of data.json.

I can't 100% verify this is exactly what was happening, but it seems to make sense given my situation and setup.

The fix for me was (assuming you're also currently using Obsidian sync and automatic Matter sync on startup):

  1. Close Obsidian on all devices and reopen it on a single device (ideally desktop cause the rest will be easier).
  2. Let Obsidian sync finish running
  3. Disable any automatic Matter sync'ing, i.e. on startup over regularly. From now on you'll manually trigger a Matter sync as it's plenty fast.
  4. Delete/rename any duplicate files in your Matter folder as needed
  5. Edit the "contentMap" in Matter's data.json to match the file name changes from the previous step
  6. Let Obsidian sync run
  7. Manually run Matter sync (e.g. from the command bar)
  8. On the other device disable internet access before opening Obsidian (otherwise the race condition will occur again!)
  9. Upon opening you'll see the Matter sync error message if you had sync on startup enabled. Ignore it.
  10. Immediately change the Matter settings to match those on your other device, i.e. manual only
  11. Renable internet access and let Obsidian sync do its thing
  12. Optional: Manually run Matter sync on this device. It should do nothing and no more duplicates should exist!