Browse Source

Micro-optimization: use `if`/`else` instead of `Array#compact` and `Array#min` (#19906)

* Technically `if`/`else` is faster than using `[value1, value2].compact.min` to find the lesser of two values, one of which may be `nil`.
closed-social-glitch-2
Postmodern 2 years ago
committed by GitHub
parent
commit
ca80beb653
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions
  1. +6
    -1
      app/models/account_statuses_cleanup_policy.rb

+ 6
- 1
app/models/account_statuses_cleanup_policy.rb View File

@ -139,7 +139,12 @@ class AccountStatusesCleanupPolicy < ApplicationRecord
# Filtering on `id` rather than `min_status_age` ago will treat
# non-snowflake statuses as older than they really are, but Mastodon
# has switched to snowflake IDs significantly over 2 years ago anyway.
max_id = [max_id, Mastodon::Snowflake.id_at(min_status_age.seconds.ago, with_random: false)].compact.min
snowflake_id = Mastodon::Snowflake.id_at(min_status_age.seconds.ago, with_random: false)
if max_id.nil? || snowflake_id < max_id
max_id = snowflake_id
end
Status.where(Status.arel_table[:id].lteq(max_id))
end

Loading…
Cancel
Save