Skip to content

Use exists? instead of find_first in boolean checking #5168

@Dijkztra

Description

@Dijkztra

Environment

  • Ruby 2.4.4
  • Rails 5.2.0
  • Devise 3.5.6

Current behaviour

Some boolean checking query use find_first method. find_first will create a select * query when run, then the result will automatically converted into ActiveRecord object by Rails.

https://apidock.com/rails/v4.0.2/ActiveRecord/FinderMethods/find_first

Location

lib/devise/models/rememberable.rb:150
lib/devise/token_generator.rb:22

Expected behavior

Using exists? method make the resulting query is select 1 and ActiveRecord doesn't need to convert the query result into a model object. Also, both Mongoid and Rails have exists? support.

https://apidock.com/rails/ActiveRecord/Base/exists%3F/class

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions