Compare commits

...

3 commits

Author SHA1 Message Date
Daniel Kempkens 7359b6f849
fix: Add indices to some tables
All checks were successful
Build / build (push) Successful in 4m2s
2023-10-24 11:08:20 +02:00
Daniel Kempkens 6bce856193
chore: Remove statistics 2023-10-24 00:25:11 +02:00
Daniel Kempkens d2cbddec40
fix: Use long date format in post listing 2023-10-20 19:56:45 +02:00
5 changed files with 13 additions and 25 deletions

View file

@ -44,8 +44,7 @@ defmodule BdfrBrowser.HTTP.Plug do
tpl_args = [
subreddit: subreddit,
dates: subreddit_record |> Post.date_listing() |> Repo.all(),
statistics: subreddit |> Subreddit.statistics() |> Repo.all()
dates: subreddit_record |> Post.date_listing() |> Repo.all()
]
content = render_template("subreddit", tpl_args)
@ -95,8 +94,7 @@ defmodule BdfrBrowser.HTTP.Plug do
tpl_args = [
subreddit: subreddit_names,
dates: subreddit_records |> Post.date_listing() |> Repo.all(),
statistics: subreddit_names |> Subreddit.statistics() |> Repo.all()
dates: subreddit_records |> Post.date_listing() |> Repo.all()
]
content = render_template("subreddit", tpl_args)

View file

@ -22,16 +22,4 @@ 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

View file

@ -0,0 +1,10 @@
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

View file

@ -55,12 +55,4 @@
<% 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>

View file

@ -31,7 +31,7 @@
<%= BdfrBrowser.RenderUtils.post_type_icon(post.url) %>
<%= post.num_comments %> comment(s)
-
<%= BdfrBrowser.RenderUtils.format_date(post.posted_at, :short) %></small>
<%= BdfrBrowser.RenderUtils.format_date(post.posted_at, :long) %></small>
</h6>
</div>
</div>