DiegoParra
DiegoParra

Reputation: 3

Which way is better in optimal terms for use Active Record query

Actually I am working in a WebSite that uses MySql DataBase and I want to know which of these two forms is better to make:

Using the object to create others queries:

@inform=Dailyinform.where(:scheduled_start => (@@datestart..@@dateend)).order("scheduled_start DESC").searchServer(@@serverSearch).searchDomain(@@domain_name)
    @[email protected](:status => 'COMPLETED').searchFailed.page(params[:page]).per_page(5000)
            @[email protected]("scheduled_start DESC").page(params[:page]).per_page(5000)

or Directly with the ActiveRecord Model - Base:

@dailyInforms=Dailyinform.where.not(:status => 'COMPLETED').where(:scheduled_start => (@@datestart..@@dateend)).order("scheduled_start DESC").searchFailed(@@serverSearch).page(params[:page]).per_page(5000)
    @restarts=Dailyinform.where(:scheduled_start => (@@datestart..@@dateend)).order("scheduled_start DESC").search2(@@serverSearch).page(params[:page]).per_page(5000)

My question arose because i felt that the second way is faster that the first way. Maybe is just my impression! Thanks

Upvotes: 0

Views: 22

Answers (1)

Albin
Albin

Reputation: 3012

When it comes to performance I don't think there will be any difference. Active record is good at being lazy when it comes to making queries, it won't perform any until you actually try to use the result.

For this reason I would say that the first method is preferable since it is more DRY.

Upvotes: 1

Related Questions