Skip to content

Commit 5d9d433

Browse files
committed
move db query from view to controller and method
1 parent 7f95109 commit 5d9d433

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

app/controllers/admin_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class AdminController < BaseAdminController
22

33
def index
4+
@networks = Network.where('protips_count_cache > 0').order('protips_count_cache desc')
45
end
56

67
def teams

app/models/network.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,8 @@ def assign_members
240240
end
241241
end
242242

243+
def recent_protips
244+
self.protips.where('created_at > ?', 1.week.ago).count
245+
end
246+
243247
end

app/views/admin/index.html.slim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@
7171
h4 Pro tips created in networks in past week
7272
section
7373
ul.networks
74-
-Network.where('protips_count_cache > 0').order('protips_count_cache desc').each do |network|
74+
-@networks.each do |network|
7575
li.network
7676
span.name= link_to network.name, network_path(network)
77-
span.created_at= network.protips.where('created_at > ?', 1.week.ago).count
77+
span.created_at= network.recent_protips
7878

7979
.widget.orange
8080
header

0 commit comments

Comments
 (0)