From b0d30e910a461e6c2ad4cbb5f6b05f6b90a6c4f2 Mon Sep 17 00:00:00 2001 From: Jeffrey Warren Date: Tue, 26 May 2020 17:34:35 -0400 Subject: [PATCH] fixes for subscription stats caching and counting (#7955) --- app/controllers/stats_controller.rb | 25 ++++++++++--------------- app/views/stats/subscriptions.html.erb | 5 +++-- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 3c97d415ef..d7c17e1267 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -1,20 +1,15 @@ class StatsController < ApplicationController def subscriptions - @tags = TagSelection.where(following: true) - .joins("LEFT JOIN community_tags ON community_tags.tid = tag_selections.tid") - .joins(:tag) - .group("term_data.name") - .count -# Rails.cache.fetch("stats/subscriptions/query", expires_in: 24.hours) do -# @tags = TagSelection.where(following: true) -# .joins("LEFT JOIN community_tags ON community_tags.tid = tag_selections.tid") -# .joins(:tag) -# .joins("INNER JOIN node ON node.nid = community_tags.nid") -# .where("node.status = 1") -# .group("term_data.name") -# .count - @tags = @tags.group_by { |_k, v| v / 10 }.sort_by { |k, _v| -k } -# end + @tags = Rails.cache.fetch("stats-subscriptions-query-1", expires_in: 24.hours) do + TagSelection.where(following: true) + .joins("LEFT JOIN community_tags ON community_tags.tid = tag_selections.tid") + .joins(:tag) + .joins("INNER JOIN node ON node.nid = community_tags.nid") + .where("node.status = 1") + .group("term_data.name") + .count + end + @tags = @tags.group_by { |_k, v| v / 10 }.sort_by { |k, _v| -k } end def range diff --git a/app/views/stats/subscriptions.html.erb b/app/views/stats/subscriptions.html.erb index 1978f7c6a4..f915789068 100644 --- a/app/views/stats/subscriptions.html.erb +++ b/app/views/stats/subscriptions.html.erb @@ -1,9 +1,10 @@
-

About this page

-

People subscribe to tags so that they can be updated when a research is posted with the tag they are subscribed to. This page shows the number of subscriptions and subscription rates on different tags.

+

About this page

+

People subscribe to tags so that they can be updated when a research is posted with the tag they are subscribed to. This page shows the number of subscriptions for every tag on the site.

Subscriptions

+

This data is cached every 24 hours.