Class: Decidim::Initiatives::InitiativeStatsPresenter

Inherits:
Rectify::Presenter
  • Object
show all
Defined in:
decidim-initiatives/app/presenters/decidim/initiatives/initiative_stats_presenter.rb

Overview

A presenter to render statistics in the homepage.

Instance Method Summary collapse

Instance Method Details

#assistants_countObject


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'decidim-initiatives/app/presenters/decidim/initiatives/initiative_stats_presenter.rb', line 27

def assistants_count
  Rails.cache.fetch(
    "initiative/#{initiative.id}/assistants_count",
    expires_in: Decidim::Initiatives.stats_cache_expiration_time
  ) do
    result = 0
    Decidim::Meetings::Meeting.where(component: meetings_component).each do |meeting|
      result += meeting.attendees_count || 0
    end

    result
  end
end

#comments_countObject


9
10
11
12
13
14
15
16
# File 'decidim-initiatives/app/presenters/decidim/initiatives/initiative_stats_presenter.rb', line 9

def comments_count
  Rails.cache.fetch(
    "initiative/#{initiative.id}/comments_count",
    expires_in: Decidim::Initiatives.stats_cache_expiration_time
  ) do
    initiative.comments_count
  end
end

#meetings_countObject


18
19
20
21
22
23
24
25
# File 'decidim-initiatives/app/presenters/decidim/initiatives/initiative_stats_presenter.rb', line 18

def meetings_count
  Rails.cache.fetch(
    "initiative/#{initiative.id}/meetings_count",
    expires_in: Decidim::Initiatives.stats_cache_expiration_time
  ) do
    Decidim::Meetings::Meeting.where(component: meetings_component).count
  end
end