add watcher count to tag on current user's profile

This commit is contained in:
byte[] 2019-12-10 19:59:43 -05:00
parent d4d4ee0e2d
commit cb6d2dff78
2 changed files with 18 additions and 0 deletions

View file

@ -10,6 +10,7 @@ defmodule PhilomenaWeb.ProfileController do
alias Philomena.Posts.Post alias Philomena.Posts.Post
alias Philomena.Comments.Comment alias Philomena.Comments.Comment
alias Philomena.Interactions alias Philomena.Interactions
alias Philomena.Tags.Tag
alias Philomena.Repo alias Philomena.Repo
import Ecto.Query import Ecto.Query
@ -36,6 +37,14 @@ defmodule PhilomenaWeb.ProfileController do
) )
tags = tags(conn.assigns.user.public_links) tags = tags(conn.assigns.user.public_links)
watcher_counts =
Tag
|> join(:inner_lateral, [t], _ in fragment("SELECT count(*) FROM users WHERE watched_tag_ids @> ARRAY[?]", t.id))
|> select([t, c], {t.id, c.count})
|> Repo.all()
|> Map.new()
recent_artwork = recent_artwork(conn, tags) recent_artwork = recent_artwork(conn, tags)
recent_comments = recent_comments =
@ -118,6 +127,7 @@ defmodule PhilomenaWeb.ProfileController do
recent_posts: recent_posts, recent_posts: recent_posts,
recent_galleries: recent_galleries, recent_galleries: recent_galleries,
statistics: statistics, statistics: statistics,
watcher_counts: watcher_counts,
about_me: about_me, about_me: about_me,
tags: tags, tags: tags,
bans: bans, bans: bans,

View file

@ -53,12 +53,20 @@
.block__header .block__header
span.block__header__title User Links span.block__header__title User Links
= for link <- @user.verified_links, link.public or can?(@conn, :edit, link) do = for link <- @user.verified_links, link.public or can?(@conn, :edit, link) do
- watchers = @watcher_counts[link.tag.id] || 0
.block__content.alternating-color.break-word .block__content.alternating-color.break-word
.center .center
= if link.tag do = if link.tag do
.tag_list = render PhilomenaWeb.TagView, "_tag.html", tag: link.tag, conn: @conn .tag_list = render PhilomenaWeb.TagView, "_tag.html", tag: link.tag, conn: @conn
= link(link.uri, to: link.uri) = link(link.uri, to: link.uri)
= if current?(@user, @conn.assigns.current_user) do
br
' Watched by
=> watchers
= pluralize("user", "users", watchers)
.block .block
.block__header .block__header
span.block__header__title Badges span.block__header__title Badges