Skip to content

Commit 56029db

Browse files
committed
Add feeds card to episode dashboard
1 parent 1052151 commit 56029db

File tree

5 files changed

+63
-9
lines changed

5 files changed

+63
-9
lines changed

app/controllers/concerns/metrics_queries.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ def daterange_downloads(model, date_start = Date.utc_today - 28.days, date_end =
2727
.load_async
2828
end
2929

30+
def downloads_by_feed(model, slugs, date_start = Date.utc_today - 28.days)
31+
model_id, column = model_attrs(model)
32+
33+
Rollups::HourlyDownload
34+
.where("#{column}": model_id, feed_slug: slugs, hour: (date_start..))
35+
.select(:feed_slug, "SUM(count) AS count")
36+
.group(:feed_slug)
37+
.order(Arel.sql("SUM(count) AS count DESC"))
38+
.final
39+
.load_async
40+
end
41+
3042
def model_attrs(model)
3143
model_id = if model.is_a?(Enumerable)
3244
model.pluck(:guid)

app/controllers/episode_metrics_controller.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,36 @@ def downloads
2020
}
2121
end
2222

23+
def feeds
24+
feed_slugs = @episode.feeds.pluck(:slug).map { |slug| slug.nil? ? "" : slug }
25+
26+
@downloads_by_feed = downloads_by_feed(@episode, feed_slugs)
27+
28+
feeds_with_downloads = []
29+
30+
@feeds = @downloads_by_feed.map do |rollup|
31+
feed = if rollup[:feed_slug].blank?
32+
@episode.podcast.default_feed
33+
else
34+
@episode.feeds.where(slug: rollup[:feed_slug]).first
35+
end
36+
37+
feeds_with_downloads << feed
38+
39+
{
40+
feed: feed,
41+
downloads: rollup
42+
}
43+
end
44+
45+
@episode.feeds.each { |feed| @feeds << {feed: feed} if feeds_with_downloads.exclude?(feed) }
46+
47+
render partial: "metrics/feeds_card", locals: {
48+
podcast: @episode.podcast,
49+
feeds: @feeds
50+
}
51+
end
52+
2353
def geos
2454
end
2555

app/controllers/podcast_metrics_controller.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,8 @@ def episodes
6060

6161
def feeds
6262
feed_slugs = @podcast.feeds.pluck(:slug).map { |slug| slug.nil? ? "" : slug }
63-
date_start = (Date.utc_today - 28.days)
6463

65-
@downloads_by_feed =
66-
Rollups::HourlyDownload
67-
.where(podcast_id: @podcast.id, feed_slug: feed_slugs, hour: (date_start..))
68-
.select(:feed_slug, "SUM(count) AS count")
69-
.group(:feed_slug)
70-
.order(Arel.sql("SUM(count) AS count DESC"))
71-
.final
72-
.load_async
64+
@downloads_by_feed = downloads_by_feed(@podcast, feed_slugs)
7365

7466
feeds_with_downloads = []
7567

app/views/episodes/_overview.html.erb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,23 @@
6262
<div class="col d-flex">
6363
<%= render "scorecard_dashboard", daterange_downloads: daterange_downloads, alltime_downloads: alltime_downloads, episode: episode %>
6464
</div>
65+
66+
<div class="row">
67+
<% if uses_multiple_feeds(episode) %>
68+
<div class="col d-grid mb-4">
69+
<div class="card shadow">
70+
<div class="card-header d-flex justify-content-between align-items-center">
71+
<span class="h4 fw-bold mb-0">Downloads by Feed</span>
72+
<span>Last 28 Days</span>
73+
</div>
74+
<div class="card-body p-0">
75+
<%= turbo_frame_tag "feeds", src: feeds_episode_metrics_path(episode_id: episode.guid), loading: "lazy", target: "_top" do %>
76+
<%= render "metrics/loading_card" %>
77+
<% end %>
78+
</div>
79+
</div>
80+
</div>
81+
<% end %>
82+
83+
</div>
6584
</div>

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
resource :transcripts, only: [:show, :update], controller: :episode_transcripts
4343
resource :metrics, only: [:show], controller: :episode_metrics do
4444
get "downloads"
45+
get "feeds"
4546
get "geos"
4647
get "agents"
4748
end

0 commit comments

Comments
 (0)