Commit 1795497822dd87fff312e56cf2e406be14ec15f8
1 parent
0029a957
Exists in
master
and in
1 other branch
Simplify User#apps & #watchers methods.
Showing
1 changed file
with
2 additions
and
7 deletions
Show diff stats
app/models/user.rb
@@ -24,10 +24,8 @@ class User | @@ -24,10 +24,8 @@ class User | ||
24 | validates_presence_of :username | 24 | validates_presence_of :username |
25 | end | 25 | end |
26 | 26 | ||
27 | - # Mongoid doesn't seem to currently support | ||
28 | - # referencing embedded documents | ||
29 | def watchers | 27 | def watchers |
30 | - App.all.map(&:watchers).flatten.select {|w| w.user_id.to_s == id.to_s} | 28 | + apps.map(&:watchers).flatten.select {|w| w.user_id.to_s == id.to_s} |
31 | end | 29 | end |
32 | 30 | ||
33 | def per_page | 31 | def per_page |
@@ -35,10 +33,7 @@ class User | @@ -35,10 +33,7 @@ class User | ||
35 | end | 33 | end |
36 | 34 | ||
37 | def apps | 35 | def apps |
38 | - # This is completely wasteful but became necessary | ||
39 | - # due to bugs in Mongoid | ||
40 | - app_ids = watchers.map {|w| w.app.id} | ||
41 | - App.any_in(:_id => app_ids) | 36 | + App.where('watchers.user_id' => id) |
42 | end | 37 | end |
43 | 38 | ||
44 | def watching?(app) | 39 | def watching?(app) |