delashum / obsidian-checklist-plugin Public
generated from obsidianmd/obsidian-sample-pluginNew 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
Data loss reported #22
Comments
|
If you're writing back to disk, you should always use |
|
I have temporarily delisted this plugin and issued a deprecation flag for all available versions. Please let me know when it's resolved so we can add it back. |
|
I'm really sorry to hear that happened. Looking into a fix right now. What is the difference between |
|
My understanding is that the main issue here was using |
|
Always use |
|
Do those two commits seem sufficient? Tested locally and works fine |
|
Let me do a quick review here. obsidian-checklist-plugin/src/_utils.ts Line 73 in a247a5c
Here you should probably use the proper API to get the file - there's one for getting the abstract file by path, just need to check if the result is instanceof TFile. Actually, why aren't you reading the file contents when toggling the item? Seems like you're working off a full copy of the file contents that you've saved sometimes earlier (which may be stale). I recommend reading the file right before writing it, and processing that version. If you think the file may/will have changed between then two, then depending on what you'd want to do, you can either work off the new version, or maybe just don't touch the file. You've set your plugin to isDesktopOnly = false, but you're using the NodeJS
Should probably use a user-agent test for isMacOS instead.
Don't use this. (You're using it more than once) It's not exposed for a good reason. Pass it in from your plugin/view. You can access it when you inherit ItemView using this.app.
More of a long term/bigger improvement down the line: obsidian-checklist-plugin/src/_utils.ts Line 18 in a247a5c
Consider avoiding re-parse every single file on every rerender? Our API can give specific file changes and you could use to incrementally update your parsed files (delete/rename from vault, new/change from metadataCache). |
|
So the specific case of data loss I believe is caused by a race-condition that you aren't testing for generally: when a file is changed locally, its |
|
Also, just to add on: when you're parsing the tasks to display them in the view, you're better off keeping it as BUT as @lishid mentioned, treat that |
|
The reason I decided to not re-read the file before writing is that I am tracking each checklist-item by what line it's on. And if I read a file right before writing and the todo is now on a different line than what's in my cache the update won't be possible. I will think about another way to approach this though. There is definitely a race condition since there is a delay between updates and the Since there isn't really any documentation I have little insight into what the different between I am curious what's wrong with Good suggestion on using user-agent. I'll get that fixed To your last suggestion, I would love to only re-parse updated files! It is very unclear to me due to the lack of documentation on how to listen for those sort of changes, so i opted to just re-parse everything each time. |
Yeah I think for this, you should probably compare the read file with the one you have cached, and bail with a
Do this: let file = vault.getAbstractFileByPath(path);
if (file instanceof TFile) {
//... your code here ...
}
The ones we're internally using for incrementally generating search results and backlinks, is something like the following: vault.on('delete') => remove the file |
|
Awesome, thanks for the helpful responses. This gives me a lot more information to work with. I apologize again for losing one of your users data, that sucks. I should be able to find some time this week to make all these changes. Also, I would be happy to help write some documentation on the Plug-in API if that's something you are interested in happening. There are quite a few things that were really unclear to me that I think could help prevent this sort of thing going forward. |
|
No worries! Awesome work and appreciate the quick response. In the end it's not your fault, we should have more actively pushed our users to backup their data. Which we will! Liam is working on some FAQ on the docs, which might be of interest to you. Would be great if you can participate once you have more time. |
|
Really hope you can get this working @delashum. This plugin is one of my favorites! |
|
@lishid what needs to happen to get this back on the store? I just released |
|
I can add it back to the plugin list. |
|
|
|
@brandonxoliver I think you meant |
https://forum.obsidian.md/t/data-loss-0-11-3-zero-byte-md-file-in-vault/13538/10
This is caused by the code at:
obsidian-checklist-plugin/src/_utils.ts
Line 236 in 9ddf1f4
cachedDataisundefinedwhen the file has not been read this session. Don't use private APIs like this.Recommended fix: Use
vault.readif you're going to be making changes and writing it back to the file.The text was updated successfully, but these errors were encountered: