Skip to content

Commit 4607233

Browse files
authored
Merge pull request #235 from coderdojo-japan/distinct-joins
Refactor dojo count
2 parents 69596ee + 7126055 commit 4607233

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

app/controllers/static_pages_controller.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ def stats
2020
@range = 2012..2017
2121
@range.each do |year|
2222
@dojos[year] =
23-
Dojo.where(created_at: Time.zone.local(2012).beginning_of_year..Time.zone.local(year)
24-
.end_of_year).select{|d| d.dojo_event_services.any?}.count
23+
Dojo
24+
.distinct
25+
.joins(:dojo_event_services)
26+
.where(created_at: Time.zone.local(@range.first).beginning_of_year..Time.zone.local(year).end_of_year)
27+
.count
2528
@events[year] =
2629
EventHistory.where(evented_at:
2730
Time.zone.local(year).beginning_of_year..Time.zone.local(year).end_of_year).count

0 commit comments

Comments
 (0)