trganda / obsidian-attachment-management

Attachment Management of Obsidian
MIT License
143 stars 8 forks source link

Dropping multiple files at once causes some kind of timing issue #46

Closed luckman212 closed 11 months ago

luckman212 commented 11 months ago

Hi @trganda

I am currently using your plugin v0.7.6 + Obsidian 1.4.2.

(But, this has been happening with older versions of both, I just have not reported it.)

Basically, when dragging and dropping a group of images onto a note, it seems there is some timing issue happening where the plugin does not update all references to the newly renamed images. So it breaks things. Maybe you need to wrap async/await somewhere? Just guessing

Here are my settings:

image

And, an example from just now of this case:

image

Here are the real files on the disk, the top window is where I dragged the files from (source) and the bottom window is the vault attachment folder that was created. As you can see, all images were processed/renamed, but the .md file did not get updated to reflect all the new filenames - only half of them did... so I have to manually correct this

image
trganda commented 11 months ago

Tks for report this problem, I have never test it 😄. I will review my code

trganda commented 11 months ago

Hi, @luckman212. It's a bad info that I can not resolved this issues.

I have no found Obsidian 1.4.2 but tested on Obsidian 1.3.7 a lot of. This problem may be caused by the api renameFile

I have already used await on it

await this.app.fileManager.renameFile(file, dst);

and tried

this.app.fileManager.renameFile(file, dst).then(...)

But it's still not working.

Normally, the renameFile will rename the file to dst path and update the properites of file for future processing. However, if the issuses happen, the file was not change anymore and no error will be catch. In my machine (8 cores), this problem will produce randomly if I drop a lot of file (about 20+).

I have tried some way to fix but all failed.

Btw, I will still pay attention to this issuses.

trganda commented 11 months ago

I have tried another api, DataAdapter.rename and retested on my pc. I'm not sure whether this can solve the issues on your position.

But please upgrade to https://github.com/trganda/obsidian-attachment-management/releases/tag/0.7.7 and try again.

luckman212 commented 11 months ago

Working great! @trganda I just stress tested it by dropping 50 files at once onto the note, and it did not miss any of them. Thank you so much for looking into this and coming up with this fix! 🙏

trganda commented 11 months ago

Happy to hear that!