Files
nairobi/app/controllers/stats_controller.rb
Javi Martín f87d4b589d Add and apply Naming/BlockForwarding rubocop rule
This syntax has been added in Ruby 3.1.

Not using a variable name might not be very descriptive, but it's just
as descriptive as using "block" as a variable name. Using just `&` we
get the same amount of information than using `&block`: that we're
passing a block.

We're still using `&action` in `around_action` methods because here we
aren't using a generic name for the variable, so (at least for now) we
aren't running this cop on controllers using `around_action`.
2023-09-12 15:17:28 +02:00

30 lines
1.1 KiB
Ruby

class StatsController < ApplicationController
include FeatureFlags
feature_flag :public_stats
skip_authorization_check
def index
@visits = daily_cache("visits") { Visit.count }
@debates = daily_cache("debates") { Debate.with_hidden.count }
@proposals = daily_cache("proposals") { Proposal.with_hidden.count }
@comments = daily_cache("comments") { Comment.not_valuations.with_hidden.count }
@debate_votes = daily_cache("debate_votes") { Vote.count_for("Debate") }
@proposal_votes = daily_cache("proposal_votes") { Vote.count_for("Proposal") }
@comment_votes = daily_cache("comment_votes") { Vote.count_for("Comment") }
@investment_votes = daily_cache("budget_investment_votes") { Vote.count_for("Budget::Investment") }
@votes = daily_cache("votes") { Vote.count }
@verified_users = daily_cache("verified_users") { User.with_hidden.level_two_or_three_verified.count }
@unverified_users = daily_cache("unverified_users") { User.with_hidden.unverified.count }
end
private
def daily_cache(key, &)
Rails.cache.fetch("public_stats/#{Time.current.strftime("%Y-%m-%d")}/#{key}", &)
end
end