Permalink
Browse files

Improve user.files_count query performance

  • Loading branch information...
1 parent 5fc3237 commit 90d09f53b061100e1ece99a6517d79b3dc628bdd @rwdaigle committed Oct 9, 2012
Showing with 2 additions and 1 deletion.
  1. +2 −1 app/models/user.rb
View
@@ -3,6 +3,7 @@ class User < ActiveRecord::Base
attr_accessible :gh_id, :gh_email, :gh_name, :gh_avatar_url, :gh_oauth_token, :gh_url, :gh_username
has_many :gists, :dependent => :destroy
+ has_many :files, :through => :gists
scope :last_fetched_before, lambda { |since| where(["last_gh_fetch < ? OR last_gh_fetch IS NULL", since])}
@@ -32,7 +33,7 @@ def gists_count
end
def files_count
- @files_count ||= gists.includes(:files).sum { |g| g.files.size }
+ @files_count ||= files.count
end
def fetched?

0 comments on commit 90d09f5

Please sign in to comment.