There are many attachments that are not cited by the notes. How do I delete them?

This feature is not working:
Resources that are not attached to any note will be automatically deleted after 10 days

How can I delete attachments that are not cited by any notes? Thank you

image

There are many attachments that are not cited by the notes. How do I delete them?

Help

There’s delete button right there on that screen. At least it’s there for me.

But you should be carfeul with that – definitely make a backup before deleting anything.

That screen is broken for me – shows attachments that are in fact used. It can easily be verified by pasting an id into the search input.

It shows all attachments, even those that are used.

How can I delete an attachment that is not referenced by any notes when there are hundreds of attachments? It’s too difficult

“Resources that are not attached to any note will be automatically deleted after 10 days”
Did not work, can it be fixed? Thank you

Ah thanks, didn’t notice that.

Still at least for me the database somehow ended up in an incosistent state.
For instance:

select * from note_resources where resource_id="04e149f4c0794427ad66d0a2cdbcf27b"

gives me this

id note_id resource_id is_associated last_seen_time
8 04e149f4c0794427ad66d0a2cdbcf27b 0
92 28b54093a4fd4deda4d2f58ec470e792 04e149f4c0794427ad66d0a2cdbcf27b 1 1587934338632

Or another issue:

select * from note_resources where resource_id="5d6c7dcd7b99465ca3aac84e0d63ce9e"

returns

188		5d6c7dcd7b99465ca3aac84e0d63ce9e	0	0

but then searching for this id in notes select count(*) from notes where body like "%5d6c7dcd7b99465ca3aac84e0d63ce9e%" returns 1 note that is not deleted.

I’ve not found the root cause yet but I suspect that the issue may occur if the ResourceService kicks in while a sync is running.

For the second issue, it’s still the same resource issue I’ve linked to in another thread.

It can happen if a resource is attached to a note, then the note is deleted before the ResourceService has time to run. In that situation it’s not possible to know if the resource is still linked to a note or not (even if it’s not attached to any local note, it could be attached to a note that has not been synced yet).

I’ve mentioned a fix for this in the GitHub issue.

Can I add a button so that users can actively delete attachments that are not referenced by notes?
Or delete the unreferenced attachment after 10 days and add a switch, users who need it can turn it on, in order to run automatically

For now unfortunately you’ll either have to delete the resources from the resource list, or wait for a fix.

When exporting jex, will attachments that are not referenced not be exported? Thank you

Please see Are images deleted if they are no longer included in any note? the title mentions images, but the same applies for any resources. there’s also some tools in the discussion about handling deleting resources.

1 Like

Do you mean this one? orphaned resources don’t get deleted · Issue #932 · laurent22/joplin · GitHub
I do not see how it's the same. In my case the resource looks like it's not used but in fact it is.

I’d need to check but I think if last_seen_time is not set it means that we don’t know if it’s used or not, so it won’t be automatically deleted. So I think it’s the same, it’s one of these resources that will never be deleted, even if you delete the associated note.

Indeed it won’t be deleted (not that I want it to be since it’s used).
Do you think it would make sense to periodically scan through notes’ contents to find such notes and repair the database? Or maybe it’s better to do it when saving a note, this way Joplin needs to scan just one note rather than all of them.

That can’t work because if a resource is not associated with a note, it might just be that the note hasn’t been downloaded via sync yet.

The ResourceService is tracking changes to know what can really be deleted or not, but it just fails in the case mentioned above.

This post is deleted through the SQL script, please ask: How does Joplin for Windows execute SQL steps? Thank you

Is there a way to manually initiate the ResourceService? Would quiting and restarting the application kick that off?

A common use case for me is deleting large unwanted jpgs/gifs etc from a not as to not take up unneeded room or even going to the attachments section and sorting by largest to cull large attachments. I then go to that note and delete the reference. At this point should I wait for that ResourceService or just delete the attachment manually from the attachments view?