Skip to content

Conversation

@italomatos
Copy link
Contributor

Simplifies the last_event method in ActivitySpike::Detector by using the more idiomatic Rails pattern .order(:created_at).last instead of .order(created_at: :desc).first. Both generate the same SQL query but .last is more readable and conventional in Rails codebases.

fizzy(dev):002> Card.last.events.order(:created_at).last
  CACHE Card Load (0.1ms)  SELECT "cards".* FROM "cards" ORDER BY "cards"."id" DESC LIMIT ?  [["LIMIT", 1]]
  Event Load (1.0ms)  SELECT "events".* FROM "events" WHERE "events"."eventable_id" = ? AND "events"."eventable_type" = ? ORDER BY "events"."created_at" DESC LIMIT ?  [["eventable_id", "<16 bytes of binary data>"], ["eventable_type", "Card"], ["LIMIT", 1]]
fizzy(dev):001> Card.last.events.order(created_at: :desc).first
  Card Load (0.3ms)  SELECT "cards".* FROM "cards" ORDER BY "cards"."id" DESC LIMIT ?  [["LIMIT", 1]]
  Event Load (0.8ms)  SELECT "events".* FROM "events" WHERE "events"."eventable_id" = ? AND "events"."eventable_type" = ? ORDER BY "events"."created_at" DESC LIMIT ?  [["eventable_id", "<16 bytes of binary data>"], ["eventable_type", "Card"], ["LIMIT", 1]]

Simplifies the last_event method in ActivitySpike::Detector by using
the more idiomatic Rails pattern .order(:created_at).last instead of
.order(created_at: :desc).first. Both generate the same SQL query but
.last is more readable and conventional in Rails codebases.
@jeremy jeremy merged commit 0833c52 into basecamp:main Dec 12, 2025
4 checks passed
olivaresf added a commit that referenced this pull request Dec 12, 2025
* origin/main: (67 commits)
  Wrap join code redemption in a lock
  Remove redundant include
  Replace custom code generator with Base32
  Test that you can't go to the magic link screen without an email
  Bundle drift detection and correction (#2101)
  Refactor: Use Rails range syntax in ActivitySpike query (#2080)
  Fix indentation in multi_db.rb initializer (#2082)
  Fix typo in translate property in card columns CSS (#2090)
  Refactor: use idiomatic .last instead of .order(:desc).first (#2098)
  bin/bundle-both (#2100)
  API: Allow updates to `last_active_at` (#2076)
  Move email address into hint line
  Bump fizzy-saas to pickup another staging change.
  Remove the rails credentials from .gitattributes
  Fix typo: minues → minutes
  Fix duplicate word: use use → use
  Add QrCodesController test
  Fix typo in _entropy.html.erb
  Show the email address you are signing in with
  Prohibit access to magic links unless an email address
  ...

# Conflicts:
#	app/controllers/sessions/magic_links_controller.rb
#	app/controllers/sessions_controller.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants