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 | 24 | validates_presence_of :username |
25 | 25 | end |
26 | 26 | |
27 | - # Mongoid doesn't seem to currently support | |
28 | - # referencing embedded documents | |
29 | 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 | 29 | end |
32 | 30 | |
33 | 31 | def per_page |
... | ... | @@ -35,10 +33,7 @@ class User |
35 | 33 | end |
36 | 34 | |
37 | 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 | 37 | end |
43 | 38 | |
44 | 39 | def watching?(app) | ... | ... |