-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
310 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module CleanUpUnusedAttachments | ||
def self.perform | ||
S3File | ||
.attachments | ||
.where('became_unused_at < ?', 24.hours.ago) | ||
.where(do_not_delete_unused: false) | ||
.find_each do |s3_file| | ||
# Double check became_unused_at | ||
s3_file.update_unused | ||
s3_file.destroy! if s3_file.unused? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
class DocumentsS3File < ApplicationRecord | ||
belongs_to :document | ||
belongs_to :s3_file | ||
|
||
after_commit :update_s3_file_unused | ||
|
||
def update_s3_file_unused | ||
s3_file.update_unused unless s3_file.destroyed? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
db/migrate/20231125213413_add_became_unused_at_to_s3_files.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class AddBecameUnusedAtToS3Files < ActiveRecord::Migration[7.0] | ||
def up | ||
add_column :s3_files, :became_unused_at, :timestamp, null: true | ||
add_column :s3_files, :do_not_delete_unused, :boolean, null: false, default: false | ||
|
||
# Flag all existing files as "do not delete" | ||
S3File.attachments.update_all(do_not_delete_unused: true) | ||
|
||
S3File.find_each(&:update_unused) | ||
end | ||
|
||
def down | ||
remove_column :s3_files, :became_unused_at | ||
remove_column :s3_files, :do_not_delete_unused | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddIdToDocumentsS3Files < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :documents_s3_files, :id, :primary_key | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.