Skip to content

Commit

Permalink
Add Rake task to cleanup old unattached blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed Oct 27, 2023
1 parent 43a5fc5 commit 5d6ab94
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ bundle exec rails decidim:robots:replace

You can see more details about this change on PR [\#11693](https://github.com/decidim/decidim/pull/11693)

### 3.12 Clean up orphaned attachment blobs

We have added a new task that helps you clean the orphaned attachment blobs. This task will remove all the attachment blobs that are not referenced by any attachment record. This helps cleaning your filesystem of unused files.

You can run the task with the following command:

```bash
bundle exec decidim:attachmens:cleanup
```

You can see more details about this change on PR [\#11851](https://github.com/decidim/decidim/pull/11851)

## 4. Scheduled tasks

Implementers need to configure these changes it in your scheduler task system in the production server. We give the examples
Expand Down
14 changes: 14 additions & 0 deletions decidim-core/lib/tasks/decidim_attachments.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

namespace :decidim do
namespace :attachmens do
desc "Cleanup the orphaned blobs attachments"
task cleanup: :environment do
ActiveStorage::Blob.includes(:attachments).find_each do |blob|
next if blob.attachments.any?

blob.purge
end
end
end
end

0 comments on commit 5d6ab94

Please sign in to comment.