mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
add watcher count to tag on current user's profile
This commit is contained in:
parent
d4d4ee0e2d
commit
cb6d2dff78
2 changed files with 18 additions and 0 deletions
|
@ -10,6 +10,7 @@ defmodule PhilomenaWeb.ProfileController do
|
|||
alias Philomena.Posts.Post
|
||||
alias Philomena.Comments.Comment
|
||||
alias Philomena.Interactions
|
||||
alias Philomena.Tags.Tag
|
||||
alias Philomena.Repo
|
||||
import Ecto.Query
|
||||
|
||||
|
@ -36,6 +37,14 @@ defmodule PhilomenaWeb.ProfileController do
|
|||
)
|
||||
|
||||
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_comments =
|
||||
|
@ -118,6 +127,7 @@ defmodule PhilomenaWeb.ProfileController do
|
|||
recent_posts: recent_posts,
|
||||
recent_galleries: recent_galleries,
|
||||
statistics: statistics,
|
||||
watcher_counts: watcher_counts,
|
||||
about_me: about_me,
|
||||
tags: tags,
|
||||
bans: bans,
|
||||
|
|
|
@ -53,12 +53,20 @@
|
|||
.block__header
|
||||
span.block__header__title User Links
|
||||
= 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
|
||||
.center
|
||||
= if link.tag do
|
||||
.tag_list = render PhilomenaWeb.TagView, "_tag.html", tag: link.tag, conn: @conn
|
||||
= link(link.uri, to: link.uri)
|
||||
|
||||
= if current?(@user, @conn.assigns.current_user) do
|
||||
br
|
||||
' Watched by
|
||||
=> watchers
|
||||
= pluralize("user", "users", watchers)
|
||||
|
||||
.block
|
||||
.block__header
|
||||
span.block__header__title Badges
|
||||
|
|
Loading…
Reference in a new issue