Skip to content

Commit

Permalink
Merge pull request #33 from blocknotes/fix/remove-queries-with-max-id
Browse files Browse the repository at this point in the history
fix: remove queries with max id
  • Loading branch information
blocknotes authored Oct 22, 2023
2 parents 65a0bb7 + c6a5401 commit 12faf23
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tasks/active_storage_db_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace :asdb do
desc 'ActiveStorageDB: list attachments ordered by blob id desc'
task list: [:environment] do |_t, _args|
query = ::ActiveStorage::Blob.order(id: :desc).limit(100)
digits = Math.log(query.maximum(:id), 10).to_i + 1
digits = query.ids.inject(0) { |ret, id| size = id.to_s.size; [size, ret].max }

::ActiveStorage::Tasks.print_blob_header(digits: digits)
query.each do |blob|
Expand Down Expand Up @@ -52,7 +52,7 @@ namespace :asdb do

blobs = ::ActiveStorage::Blob.where('filename LIKE ?', "%#{filename}%").order(id: :desc)
if blobs.any?
digits = Math.log(blobs.first.id, 10).to_i + 1
digits = blobs.ids.inject(0) { |ret, id| size = id.to_s.size; [size, ret].max }
::ActiveStorage::Tasks.print_blob_header(digits: digits)
blobs.each do |blob|
::ActiveStorage::Tasks.print_blob(blob, digits: digits)
Expand Down

0 comments on commit 12faf23

Please sign in to comment.