readwise-mirror
readwise-mirror copied to clipboard
refactor: :recycle: use process() method to write new content
Use the Vault.process()
method to atomically read, modify, and save the contents of existing notes when updating from Readwise, instead of completely deleting and recreating the files. Should improve overall compatibility with other plugins, i.e. in the case of parallel edits.
The switch from getAbstractFileByPath()
to getFileByPath()
should simplify things without compromising functionalty.
N.B.: Besides making use of a standard API instead of deleting and recreating a file, changing to the process()
method would in principle open the path to the following ideas as well:
- Keep frontmatter for existing notes (or merge it, e.g. for updated fields), and
- Attempt to merge local and remote changes (I am working on an approach for that, but it's a tricky thing), or, looking at requests like #24,
- Other magic to properly manipulate the existing content.
@johannrichard good idea, I agree modification is a better strategy. Even if the markdown diff reconciliation solution doesn't pan out, this still looks like a better method to implement file modification operations.