Skip to content
Browse files

Simplify User#apps & #watchers methods.

  • Loading branch information...
1 parent 0029a95 commit 1795497822dd87fff312e56cf2e406be14ec15f8 @oruen oruen committed Aug 12, 2011
Showing with 2 additions and 7 deletions.
  1. +2 −7 app/models/user.rb
View
9 app/models/user.rb
@@ -24,21 +24,16 @@ class User
validates_presence_of :username
end
- # Mongoid doesn't seem to currently support
- # referencing embedded documents
def watchers
- App.all.map(&:watchers).flatten.select {|w| w.user_id.to_s == id.to_s}
+ apps.map(&:watchers).flatten.select {|w| w.user_id.to_s == id.to_s}
end
def per_page
self[:per_page] || PER_PAGE
end
def apps
- # This is completely wasteful but became necessary
- # due to bugs in Mongoid
- app_ids = watchers.map {|w| w.app.id}
- App.any_in(:_id => app_ids)
+ App.where('watchers.user_id' => id)
end
def watching?(app)

0 comments on commit 1795497

Please sign in to comment.
Something went wrong with that request. Please try again.