From 1795497822dd87fff312e56cf2e406be14ec15f8 Mon Sep 17 00:00:00 2001 From: Nick Recobra Date: Fri, 12 Aug 2011 00:55:33 +0400 Subject: [PATCH] Simplify User#apps & #watchers methods. --- app/models/user.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 33cc157..a12b896 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -24,10 +24,8 @@ 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 @@ -35,10 +33,7 @@ class User 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) -- libgit2 0.21.2