Skip to content

Commit

Permalink
fixes for subscription stats caching and counting (#7955)
Browse files Browse the repository at this point in the history
  • Loading branch information
jywarren authored May 26, 2020
1 parent d56f44f commit b0d30e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
25 changes: 10 additions & 15 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions app/views/stats/subscriptions.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<div class="col-lg-3">
<h4> About this page </h4>
<p> 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. </p>
<h4>About this page </h4>
<p>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. </p>
</div>
<div class="col-lg-8 col-lg-offset-1">
<h2>Subscriptions</h2>
<p>This data is cached every 24 hours.</p>
<table class="table inline-grid">
<tr>
<thead>
Expand Down

0 comments on commit b0d30e9

Please sign in to comment.