Compare commits
No commits in common. "7359b6f84910d2742fef0f8ce45fdd6e3cd39594" and "6d9db86e30f6e73cbc0929926bc45c626c2d25d0" have entirely different histories.
7359b6f849
...
6d9db86e30
5 changed files with 25 additions and 13 deletions
|
@ -44,7 +44,8 @@ defmodule BdfrBrowser.HTTP.Plug do
|
|||
|
||||
tpl_args = [
|
||||
subreddit: subreddit,
|
||||
dates: subreddit_record |> Post.date_listing() |> Repo.all()
|
||||
dates: subreddit_record |> Post.date_listing() |> Repo.all(),
|
||||
statistics: subreddit |> Subreddit.statistics() |> Repo.all()
|
||||
]
|
||||
|
||||
content = render_template("subreddit", tpl_args)
|
||||
|
@ -94,7 +95,8 @@ defmodule BdfrBrowser.HTTP.Plug do
|
|||
|
||||
tpl_args = [
|
||||
subreddit: subreddit_names,
|
||||
dates: subreddit_records |> Post.date_listing() |> Repo.all()
|
||||
dates: subreddit_records |> Post.date_listing() |> Repo.all(),
|
||||
statistics: subreddit_names |> Subreddit.statistics() |> Repo.all()
|
||||
]
|
||||
|
||||
content = render_template("subreddit", tpl_args)
|
||||
|
|
|
@ -22,4 +22,16 @@ defmodule BdfrBrowser.Subreddit do
|
|||
def names_without(hidden) do
|
||||
from(s in __MODULE__, select: s.name, where: s.name not in ^hidden, order_by: [asc: fragment("lower(?)", s.name)])
|
||||
end
|
||||
|
||||
def statistics(subreddit) when is_binary(subreddit), do: statistics([subreddit])
|
||||
|
||||
def statistics(subreddits) when is_list(subreddits) do
|
||||
from(s in __MODULE__,
|
||||
join: p in assoc(s, :posts),
|
||||
left_join: c in assoc(p, :comments),
|
||||
select: {s.name, count(p.id), count(c.id)},
|
||||
where: s.name in ^subreddits,
|
||||
group_by: [s.name]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
defmodule BdfrBrowser.Repo.Migrations.AddIndicesToMultipleTables do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create index("posts", :author)
|
||||
create index("posts", :posted_at)
|
||||
create index("comments", :author)
|
||||
create index("chats", :accounts)
|
||||
end
|
||||
end
|
|
@ -55,4 +55,12 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="d-grid gap-2 col-12 mx-auto">
|
||||
<p class="text-secondary">
|
||||
<%= for {name, post_count, comment_count} <- statistics do %>
|
||||
<%= name %>: <%= post_count %> Posts; <%= comment_count %> Comments<br />
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<%= BdfrBrowser.RenderUtils.post_type_icon(post.url) %>
|
||||
<%= post.num_comments %> comment(s)
|
||||
-
|
||||
<%= BdfrBrowser.RenderUtils.format_date(post.posted_at, :long) %></small>
|
||||
<%= BdfrBrowser.RenderUtils.format_date(post.posted_at, :short) %></small>
|
||||
</h6>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Reference in a new issue