Prevent duplicate files for existing Readwise books#99
Draft
javenfang wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR prevents the Obsidian plugin from creating a new suffixed Markdown file when an export artifact contains a filename for a book that the vault already knows by
book_id.The plugin now resolves the write target through the existing
booksIDsMapbefore writing highlight files. If the same book ID already has a known vault path, the sync updates that stable path instead of trusting a newly exported path such asBook Title (467).md.User impact / bug report
This comes from a recurring real-world sync failure in a private Obsidian vault. The vault repeatedly accumulated numeric-suffix duplicates under
Readwise/, for example paths shaped likeTitle (467).mdandTitle (485).md. In one cleanup pass, there were 624 duplicate Markdown files across three stable Readwise book/document IDs, with 208 suffixed copies per ID.The pattern suggests the export artifact can sometimes contain a new suffixed filename for content that is already represented in the vault. Since the current plugin maps
filePath -> bookIDand writes to the artifact filename directly, those suffixed filenames become new files even when the samebook_idalready exists locally.What changed
stablePathForBookExport()to choose the existing path for the same book ID before creating a new file.Validation
npm testnpm run typechecknpm run build