# Do attachments (pictures) unattached to any note get deleted, if Note History is disabled?

**URL:** <https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308>\
**Category:** Support\
**Created:** [18 January 2024 22:21 UTC](https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308 "2024-01-18T22:21:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aidar](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/aidar/32/19646_2.png) [@Aidar](https://discourse.joplinapp.org/u/Aidar)\
**Post date:** [18 January 2024 22:21 UTC](https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308/1 "2024-01-18T22:21:22Z")

</div>

### Operating system

Windows

### Joplin version

2.14.8

### What issue do you have?

“Resources that are not attached to any note will be automatically deleted in accordance to the Note History settings”, according to https:// joplinapp . org /help/apps/attachments

“If a resource is associated with any note, is\_associated is 1, it it’s not is\_associated is 0. From the moment is\_associated is 0, a timer starts and after x days the resource is deleted”, as described in https:// discourse . joplinapp . org /t/is-there-a-way-to-force-joplin-to-run-the-unused-resources-cleanup/3758/23

When one clips a web-page or its fragment using Web Clipper, some irrelevant ad banners (pictures) end up in the newly created note. One then manually deletes such pictures, usually a few per note.  
Do such attachments (pictures), no longer associated with any note, still get automatically deleted someday, if Note History feature is disabled, and therefore a cleanup routine that deletes old notes from the Note History may not be required to run?

Thank you.

---

<div class="post-metadata">

**Author:** ![HarSel](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/harsel/32/13486_2.png) [@HarSel](https://discourse.joplinapp.org/u/HarSel)\
**Post date:** [18 January 2024 22:26 UTC](https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308/2 "2024-01-18T22:26:59Z")

</div>

No. I've always had history turned off and still have images floating around that have been there for years. I have to delete them manually and clipping a Web page with dozens of images can make for a fairly tedious task. Delete image, scroll to next one, delete that, repeat.

---

<div class="post-metadata">

**Author:** ![personalizedrefriger](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/personalizedrefriger/32/13210_2.png) [@personalizedrefriger](https://discourse.joplinapp.org/u/personalizedrefriger)\
**Post date:** [18 January 2024 22:45 UTC](https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308/3 "2024-01-18T22:45:51Z")

</div>

> **From local testing, resources do seem to be automatically deleted when note history is disabled (though as per @HarSel's comment perhaps there's a bug that causes them not to be deleted in some cases).
The amount of time they're kept still seems to be based on the Keep note history for (days) setting (even when note history is off).**
>
> Summary of testing:
> 
> 1. Started Joplin 2.14.9 (dev mode)
> 2. Created a note
> 3. Attached an image
> 4. Disabled note history
> 5. Set "keep note history for (days)" to 1
> 6. Copied the resource ID (eb1119675151422eb060c62ed84c8bc1)
> 7. Closed Joplin
> 8. Re-opened Joplin
> 9. Opened the development tools and searched for `ResourceService::deleteOrphanResources`
> 10. Waited about 30 seconds
> 11. Saw `ResourceService::deleteOrphanResources` with no resources
> 12. Closed Joplin
> 13. Set the system date/time to Jan 30 2024 @ 2:40 PM (several weeks in the future)
> - **DANGER:** Avoid doing this if Joplin syncs to anything or has notes you care about — Joplin seems to use timestamps for sync, so this may lead to sync issues/data loss.
> 
> 14. Deleted the resource from the note and closed Joplin
> 15. Set the date to February 29th and re-opened Joplin
> 16. Opened the development tools and searched for `ResourceService::deleteOrphanResources`
> 17. Waited roughly 30 seconds
> 18. Saw `ResourceService::deleteOrphanResources: eb1119675151422eb060c62ed84c8bc1` in the log
> 19. Checked "Note attachments" for the resource (it's gone!)

As such, setting `Keep note history for (days)` to `1` and disabling note history **should** delete unlinked attachments after roughly one day.

Just before resources are deleted, a line starting with `ResourceService::deleteOrphanResources:` should be added to the log that includes which resources were deleted.

See also:

- [Code that handles orphaned resource deletion](https://github.com/laurent22/joplin/blob/3ed6ad594841566a4152a8dd2b12eaa9ab9d4dc8/packages/lib/services/ResourceService.ts#L119)
  - Observe that the code references the `revisionService.ttlDays` setting (which seems to have a minimum value of 1, despite being changeable to `0` in settings).

- [Code that schedules orphaned resource deletion](https://github.com/laurent22/joplin/blob/3ed6ad594841566a4152a8dd2b12eaa9ab9d4dc8/packages/lib/services/ResourceService.ts#L171)
  - Orphaned resources should be deleted 30 seconds after opening the application, then every four hours.

- [Original post with similar information to the above](https://discourse.joplinapp.org/t/tessus-joplin-cleanup-script-for-orphan-resources-nuked-everything/34708/3)

---

<div class="post-metadata">

**Author:** ![HarSel](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/harsel/32/13486_2.png) [@HarSel](https://discourse.joplinapp.org/u/HarSel)\
**Post date:** [18 January 2024 23:32 UTC](https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308/4 "2024-01-18T23:32:57Z")

</div>

> [@personalizedrefriger](#):
>
> From local testing, resources do seem to be automatically deleted when note history is disabled

Whenever I add a new device (phone/tablet etc.) there are 3 images that get created as part of the new "Welcome" notebook on that device. These get synced to the target even if the "Welcome" notebook was deleted before the sync. History on my PC (and the mobile) is always disabled yet these 3 images are permanent until I go in via "Note Attachments" and delete them manually. History setting makes no difference, those are never removed automatically nor are images I myself attached to notes and then deleted the notes. Images seem to remain until I do an export-uninstall-delete-install-import cycle. Could partly explain why I have only 2600 notes but must fetch 35,000 resources when I sync a new device for the first time.

---

<div class="post-metadata">

**Author:** ![HarSel](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/harsel/32/13486_2.png) [@HarSel](https://discourse.joplinapp.org/u/HarSel)\
**Post date:** [18 January 2024 23:39 UTC](https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308/5 "2024-01-18T23:39:58Z")

</div>

> [@personalizedrefriger](#):
>
> The amount of time they're kept still seems to be based on the `Keep note history for (days)` setting (even when note history is off).

I have tried this both ways, setting history to 1 day with history on and the same with history off. Images are still there weeks later no matter the setting. I have to do an export-import routine every month to keep the clutter under control.

---

<div class="post-metadata">

**Author:** ![personalizedrefriger](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/personalizedrefriger/32/13210_2.png) [@personalizedrefriger](https://discourse.joplinapp.org/u/personalizedrefriger)\
**Post date:** [19 January 2024 00:43 UTC](https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308/6 "2024-01-19T00:43:50Z")

</div>

One possibility is that Joplin deletes resources locally then re-downloads them from the sync target.

Checking the log\[1\] for lines starting with `ResourceService::deleteOrphanResources:` (then followed by a resource ID) could help show whether Joplin is trying to delete resources at all.

* * *

1. `~/.config/joplin-desktop/log.txt` on Linux and MacOS, I think `C:\Users\UserName\.config\joplin-desktop\log.txt` on Windows.

---

<div class="post-metadata">

**Author:** ![Aidar](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/aidar/32/19646_2.png) [@Aidar](https://discourse.joplinapp.org/u/Aidar)\
**Post date:** [19 January 2024 01:43 UTC](https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308/7 "2024-01-19T01:43:51Z")

</div>

@personalizedrefriger thanks a lot for the very helpful explanation!

I searched the %userprofile%`\`.config\joplin-desktop\log.txt for “ResourceService::deleteOrphanResources”.

It seems it is indeed irrelevant whether “Enable note history” checkbox is turned on or off, because I have always had it turned off.

Indeed, what matters is the value of “Keep note history for (days)”.

When I set it from “90” (default value) to “0”, upon next launch Joplin detected 600+ orphaned resources and deleted them.

As I have been using Joplin for less than 90 days, no orphaned resources were deleted via “ResourceService::deleteOrphanResources” procedure until I lowered the threshold - there had been many identical empty log entries:

> "ResourceService::deleteOrphanResources:", "`[`]"

---

<div class="post-metadata">

**Author:** ![HarSel](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/harsel/32/13486_2.png) [@HarSel](https://discourse.joplinapp.org/u/HarSel)\
**Post date:** [22 January 2024 08:27 UTC](https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308/8 "2024-01-22T08:27:14Z")

</div>

I first set it back to the 90 day default and waited a few days. I identified 6 files I could be sure were orphans (2 each of AllClients.png, SubNotebooks.png and WebClipper.png) and reset the history back down to 1 day. After 48 hours I checked again and they were still there so I set history back down to zero and waited two days until a few minutes ago. Those files are still there.

Perhaps these are considered "system" files and are thus untouchable or the note history length has no effect. Since I have never, in years and years, seen these orphaned resources automatically deleted I assumed the "Keep note history" to be a less than effective method of reducing the clutter and relied upon the manual method of exporting everything, wiping all traces of Joplin everywhere, importing everything and re-syncing 8 devices, a job that usually takes a few days.

---

<div class="post-metadata">

**Author:** ![tomasz86](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@tomasz86](https://discourse.joplinapp.org/u/tomasz86)\
**Post date:** [22 January 2024 10:37 UTC](https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308/9 "2024-01-22T10:37:11Z")

</div>

> [@personalizedrefriger](#):
>
> Observe that the code references the `revisionService.ttlDays` setting (which seems to have a minimum value of 1, despite being changeable to `0` in settings)

What happens if you set it to `0` in settings then? It it treated as the same as `1` or ignored as invalid?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/3X/1/c/1c948e33314e232a0927789508474d8624f4270b.png) [@system](https://discourse.joplinapp.org/u/system)\
**Post date:** [21 February 2024 10:37 UTC](https://discourse.joplinapp.org/t/do-attachments-pictures-unattached-to-any-note-get-deleted-if-note-history-is-disabled/35308/10 "2024-02-21T10:37:15Z")

</div>

Closed on 21 February 2024 10:37 UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
