Skip to content

Commit

Permalink
Refactor History::FinderMethods: use base implementation.
Browse files Browse the repository at this point in the history
It also makes `first_by_friendly_id` better because base implementation
in `FriendlyId::FinderMethods` uses `find_by` which is optimized in
Rails 4.2 (so called "Adequate Record").
  • Loading branch information
marshall-lee authored and parndt committed Jan 22, 2018
1 parent 4bd4300 commit fc8392e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/friendly_id/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,13 @@ module FinderMethods
include ::FriendlyId::FinderMethods

def exists_by_friendly_id?(id)
where(arel_table[friendly_id_config.query_field].eq(id)).exists? || joins(:slugs).where(slug_history_clause(id)).exists?
super || joins(:slugs).where(slug_history_clause(id)).exists?
end

private

def first_by_friendly_id(id)
matching_record = where(friendly_id_config.query_field => id).first
matching_record || slug_table_record(id)
super || slug_table_record(id)
end

def slug_table_record(id)
Expand Down

0 comments on commit fc8392e

Please sign in to comment.