From aa170313fc30ff2f833105b9e77c615791d1c312 Mon Sep 17 00:00:00 2001 From: Miha Rekar Date: Tue, 2 Jan 2024 16:17:26 +0100 Subject: [PATCH] With #pop I avoid creating a copy of the results array --- .rubocop.yml | 3 +++ Gemfile.lock | 19 +++++++++++-------- .../concerns/cursor_paginatable.rb | 6 +++--- app/jobs/airtable_webhook_job.rb | 2 +- config/environments/production.rb | 2 +- ...212_alter_espresso_enjoyment_to_integer.rb | 2 +- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b735230e..80006571 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -93,3 +93,6 @@ Style/SymbolArray: Style/WordArray: Enabled: true + +Rails/SaveBang: + Enabled: false diff --git a/Gemfile.lock b/Gemfile.lock index e831c181..d2cc0274 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -101,7 +101,7 @@ GEM rack ast (2.4.2) aws-eventstream (1.3.0) - aws-partitions (1.874.0) + aws-partitions (1.876.0) aws-sdk-core (3.190.1) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) @@ -232,12 +232,11 @@ GEM marcel (1.0.2) memo_wise (1.8.0) method_source (1.0.0) - mime-types (3.5.1) + mime-types (3.5.2) mime-types-data (~> 3.2015) mime-types-data (3.2023.1205) mini_magick (4.12.0) mini_mime (1.1.5) - mini_portile2 (2.8.5) minitest (5.20.0) msgpack (1.7.2) multi_xml (0.6.0) @@ -254,8 +253,11 @@ GEM net-protocol netrc (0.11.0) nio4r (2.7.0) - nokogiri (1.15.5) - mini_portile2 (~> 2.8.2) + nokogiri (1.16.0-aarch64-linux) + racc (~> 1.4) + nokogiri (1.16.0-arm64-darwin) + racc (~> 1.4) + nokogiri (1.16.0-x86_64-linux) racc (~> 1.4) notiffany (0.1.3) nenv (~> 0.1) @@ -387,10 +389,11 @@ GEM rubocop-performance (1.20.1) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.30.0, < 2.0) - rubocop-rails (2.20.2) + rubocop-rails (2.23.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) ruby-vips (2.2.0) ffi (~> 1.12) @@ -429,9 +432,9 @@ GEM standard-performance (1.3.0) lint_roller (~> 1.1) rubocop-performance (~> 1.20.1) - standard-rails (0.2.0) + standard-rails (1.0.0) lint_roller (~> 1.0) - rubocop-rails (~> 2.20.2) + rubocop-rails (~> 2.23.1) stimulus-rails (1.3.0) railties (>= 6.0.0) stringio (3.1.0) diff --git a/app/controllers/concerns/cursor_paginatable.rb b/app/controllers/concerns/cursor_paginatable.rb index e43bd585..81efd24d 100644 --- a/app/controllers/concerns/cursor_paginatable.rb +++ b/app/controllers/concerns/cursor_paginatable.rb @@ -3,9 +3,9 @@ module CursorPaginatable def paginate_with_cursor(relation, items: 20, before: nil, by: :id, direction: :desc) relation = relation.where(by => ..before) if before.present? - relation = relation.order(by => direction).limit(items + 1).load - cursor = relation.last.public_send(by) if relation.size > items + relation = relation.order(by => direction).limit(items + 1).to_a + cursor = relation.pop.public_send(by) if relation.size > items - [relation.take(items), cursor] + [relation, cursor] end end diff --git a/app/jobs/airtable_webhook_job.rb b/app/jobs/airtable_webhook_job.rb index b7089914..c83d857d 100644 --- a/app/jobs/airtable_webhook_job.rb +++ b/app/jobs/airtable_webhook_job.rb @@ -63,7 +63,7 @@ def download_shot_updates raise LastTransactionMismatchError if @airtable_info.reload.last_transaction.to_i != @last_transaction @airtable_info.update!( - last_transaction: @payloads.map { |p| p["baseTransactionNumber"] }.max, + last_transaction: @payloads.pluck("baseTransactionNumber").max, last_cursor: @webhook_payloads["cursor"] ) end diff --git a/config/environments/production.rb b/config/environments/production.rb index 05b8eb8b..054dc19b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -27,7 +27,7 @@ config.public_file_server.headers = { "Cache-Control" => "public, s-maxage=31536000, max-age=15552000", - "Expires" => 1.year.from_now.to_formatted_s(:rfc822) + "Expires" => 1.year.from_now.to_fs(:rfc822) } # Do not fallback to assets pipeline if a precompiled asset is missed. diff --git a/db/migrate/20210711171212_alter_espresso_enjoyment_to_integer.rb b/db/migrate/20210711171212_alter_espresso_enjoyment_to_integer.rb index c172f80d..0fec4690 100644 --- a/db/migrate/20210711171212_alter_espresso_enjoyment_to_integer.rb +++ b/db/migrate/20210711171212_alter_espresso_enjoyment_to_integer.rb @@ -7,7 +7,7 @@ class MigrationShot < ApplicationRecord def up problematic = MigrationShot.where.not(espresso_enjoyment: nil).pluck(:id, :espresso_enjoyment).reject { |_id, e| e.to_i.to_s == e } - MigrationShot.where(id: problematic.map(&:first)).each do |shot| + MigrationShot.where(id: problematic.map(&:first)).find_each do |shot| shot.update(espresso_enjoyment: shot.espresso_enjoyment.to_i) end