Skip to content

Commit

Permalink
With #pop I avoid creating a copy of the results array
Browse files Browse the repository at this point in the history
  • Loading branch information
miharekar committed Jan 2, 2024
1 parent 228b766 commit aa17031
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ Style/SymbolArray:

Style/WordArray:
Enabled: true

Rails/SaveBang:
Enabled: false
19 changes: 11 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/concerns/cursor_paginatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/jobs/airtable_webhook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit aa17031

Please sign in to comment.