Are images deleted if they are no longer included in any note?

In general, are images deleted if I delete their links from a note?

If a resource is no longer referenced, it should be deleted after 24h. But there’s a bug so this does not always happen.

This has been a problem for quite a while. Do you know if there are any plans to fix this in the near future, winter, spring?

Nope, I don’t know. But at one point Laurent mentioned something in that regard, but I can’t remember what it was.

I don’t have a solution at the moment, except maybe enforcing a one-to-one relationship between notes and resources, but even that would be tricky to implement.

Thanks. I wish I could help code a solution with you, but I’m sure the code would be over my head. I am in the process of creating a python script to clean out the resources folder of orphaned files which is going well so far. If I delete the orphaned files from the resources folder, will I also have to remove the records that reference them in the note_resources where is_associated = 0?

You shouldn’t manipluate the database manually. There are a bunch of scripts already available (check the #apps category), but removing all resources where is_associated = 0 could lead to data loss, if you’re using note history.

Ok Thanks. I guess I’ll wait for you guys to fix it properly.

any update on this ?

If this still isn’t working, I’ll write something to clear unlinked resources. Can someone please let me know so I don’t waste my time ? @tessus ?

If you check the apps category you can probably find some resources to help with that. For example tessus has some scripts for cleaning unlinked resources. Those will probably be enough for you.

1 Like

I wrote my own and I noticed it ended up deleting more stuff that @tessus’s script didn’t catch.

sudo gem install joplin and then run joplin clean --token a6f0459... to run it. also has a -n for a dry-run. Mine’s much slower because it uses the Joplin API fully

This might not be good. Are you sure you took the note history into account? If you run my script with the options --zero-history or --ignore-revisions you might see the same number of "orphans" as in your script. However, please do ONLY run this with the --dry-run option. Otherwise you will most likely lose data.

Using the notes endpoint I got resources for all notes, then using the resources endpoint I got all the resources that exist. Then I delete all the resources that didn’t exist in any notes.

I’m pretty sure there’s a bug in resource cleanup logic. Or more likely in sync logic. I mentioned elsewhere on the forum that I’ve inspected my database and found some lines in note_resources table that are obviously broken.

I’m not yet sure as to what the root cause (though I have an idea), will try to investigate further.

The problem is that I do not know, if the API actually takes the history into account either. This is something only @laurent would know - or someone who worked at the note history code.

Laurent mentioned several times that there’s a reason why the current implementation does not catch all resources. But I can’t recall the exact explanation. I think it had something to do with the n:m relationship of notes and resources.

There’s some info about this bug in this issue: https://github.com/laurent22/joplin/issues/932

Hi... A quick query.

Files/images that are no longer attached to a note are automatically deleted after 24 or 48 hours? In some places, I see 24, and in another, 48 hours.

Usecase:

  • Note A has two images added to it along with some text
  • It's all synced up to the cloud(Dropbox). The setup is E2EE.
  • I delete Note A.

So, in this case, when those two images that I added to Note A be automatically deleted?

You may have a look here: