0
這是我如何得到全計數,並@codes
對象如何加快少sql?
@codes = user.codes.joins(:community).merge(Community.not_deleted).order("codes.updated_at DESC").limit(10)
@codes_count = user.codes.joins(:community).merge(Community.not_deleted).order("codes.updated_at DESC").count
是否有任何技術使這個少SQL查詢?
像
@codes_all = user.codes.joins(:community).merge(Community.not_deleted).order("codes.updated_at DESC")
@codes_count = @codes_all.count
@codes = @codes_all.limit(10)
,並有可能使這種預先加載這樣的事情?
@codes_all = user.codes.includes(community: [:country, :language]).joins(:community).merge(Community.not_deleted).order("codes.updated_at DESC")
@codes_count = @codes_all.count
@codes = @codes_all.limit(10)