From cb6d2dff78a98fae7af5fd02c09400f1c4c527e7 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Tue, 10 Dec 2019 19:59:43 -0500 Subject: [PATCH] add watcher count to tag on current user's profile --- lib/philomena_web/controllers/profile_controller.ex | 10 ++++++++++ lib/philomena_web/templates/profile/show.html.slime | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/philomena_web/controllers/profile_controller.ex b/lib/philomena_web/controllers/profile_controller.ex index aec402ce..bba35831 100644 --- a/lib/philomena_web/controllers/profile_controller.ex +++ b/lib/philomena_web/controllers/profile_controller.ex @@ -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, diff --git a/lib/philomena_web/templates/profile/show.html.slime b/lib/philomena_web/templates/profile/show.html.slime index 3e1920fb..b0720084 100644 --- a/lib/philomena_web/templates/profile/show.html.slime +++ b/lib/philomena_web/templates/profile/show.html.slime @@ -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