From 39fe2cbd551641665370ea4027e995347cc700b6 Mon Sep 17 00:00:00 2001 From: parasprite Date: Thu, 3 Dec 2020 13:23:32 -0600 Subject: [PATCH] Fixes batch tagging messing with complex spoilers (#49) --- lib/philomena/polymorphic.ex | 4 ++-- lib/philomena_web/controllers/activity_controller.ex | 12 ++++++------ .../api/json/image/featured_controller.ex | 2 +- .../controllers/api/json/image_controller.ex | 2 +- .../controllers/api/json/oembed_controller.ex | 2 +- .../controllers/api/json/search/image_controller.ex | 2 +- .../controllers/api/rss/watched_controller.ex | 2 +- lib/philomena_web/controllers/comment_controller.ex | 2 +- .../controllers/commission_controller.ex | 2 +- .../controllers/duplicate_report_controller.ex | 2 +- .../fingerprint_profile/source_change_controller.ex | 2 +- .../fingerprint_profile/tag_change_controller.ex | 2 +- lib/philomena_web/controllers/gallery_controller.ex | 6 +++--- .../controllers/image/comment/report_controller.ex | 2 +- .../controllers/image/comment_controller.ex | 2 +- .../controllers/image/description_controller.ex | 2 +- .../controllers/image/fave_controller.ex | 2 +- .../controllers/image/related_controller.ex | 4 ++-- .../controllers/image/report_controller.ex | 2 +- .../controllers/image/reporting_controller.ex | 4 ++-- .../controllers/image/source_change_controller.ex | 2 +- .../controllers/image/source_controller.ex | 2 +- .../controllers/image/tag_change_controller.ex | 2 +- .../controllers/image/tag_controller.ex | 6 +++--- .../controllers/image/vote_controller.ex | 2 +- lib/philomena_web/controllers/image_controller.ex | 4 ++-- .../ip_profile/source_change_controller.ex | 2 +- .../controllers/ip_profile/tag_change_controller.ex | 2 +- .../profile/commission/item_controller.ex | 2 +- .../profile/commission/report_controller.ex | 2 +- .../controllers/profile/commission_controller.ex | 2 +- .../controllers/profile/source_change_controller.ex | 2 +- .../controllers/profile/tag_change_controller.ex | 2 +- lib/philomena_web/controllers/profile_controller.ex | 12 ++++++------ lib/philomena_web/controllers/search_controller.ex | 2 +- .../controllers/tag/tag_change_controller.ex | 2 +- lib/philomena_web/controllers/tag_controller.ex | 2 +- lib/philomena_web/image_reverse.ex | 2 +- lib/philomena_web/textile_renderer.ex | 2 +- lib/philomena_web/views/image_view.ex | 4 ++-- 40 files changed, 59 insertions(+), 59 deletions(-) diff --git a/lib/philomena/polymorphic.ex b/lib/philomena/polymorphic.ex index 9427b210..0293355d 100644 --- a/lib/philomena/polymorphic.ex +++ b/lib/philomena/polymorphic.ex @@ -20,12 +20,12 @@ defmodule Philomena.Polymorphic do } @preloads %{ - "Comment" => [:user, image: :tags], + "Comment" => [:user, image: [tags: :aliases]], "Commission" => [:user], "Conversation" => [:from, :to], "DnpEntry" => [:requesting_user], "Gallery" => [:creator], - "Image" => [:user, :tags], + "Image" => [:user, tags: :aliases], "Post" => [:user, topic: :forum], "Topic" => [:forum, :user], "Report" => [:user] diff --git a/lib/philomena_web/controllers/activity_controller.ex b/lib/philomena_web/controllers/activity_controller.ex index ecb4f1b5..d185fac9 100644 --- a/lib/philomena_web/controllers/activity_controller.ex +++ b/lib/philomena_web/controllers/activity_controller.ex @@ -76,7 +76,7 @@ defmodule PhilomenaWeb.ActivityController do |> filter_hidden(user, conn.params["hidden"]) |> order_by([i, f], desc: f.created_at) |> limit(1) - |> preload([:tags]) + |> preload([tags: :aliases]) |> Repo.one() streams = @@ -144,7 +144,7 @@ defmodule PhilomenaWeb.ActivityController do responses = Elasticsearch.msearch_records( [images, top_scoring, comments], - [preload(Image, :tags), preload(Image, :tags), preload(Comment, [:user, image: :tags])] + [preload(Image, tags: :aliases), preload(Image, tags: :aliases), preload(Comment, [:user, image: [tags: :aliases]])] ) responses ++ [nil] @@ -154,10 +154,10 @@ defmodule PhilomenaWeb.ActivityController do Elasticsearch.msearch_records( [images, top_scoring, comments, watched], [ - preload(Image, :tags), - preload(Image, :tags), - preload(Comment, [:user, image: :tags]), - preload(Image, :tags) + preload(Image, tags: :aliases), + preload(Image, tags: :aliases), + preload(Comment, [:user, image: [tags: :aliases]]), + preload(Image, tags: :aliases) ] ) end diff --git a/lib/philomena_web/controllers/api/json/image/featured_controller.ex b/lib/philomena_web/controllers/api/json/image/featured_controller.ex index b2cbbbb9..3287cafb 100644 --- a/lib/philomena_web/controllers/api/json/image/featured_controller.ex +++ b/lib/philomena_web/controllers/api/json/image/featured_controller.ex @@ -15,7 +15,7 @@ defmodule PhilomenaWeb.Api.Json.Image.FeaturedController do |> join(:inner, [i], f in ImageFeature, on: [image_id: i.id]) |> order_by([_i, f], desc: f.created_at) |> limit(1) - |> preload([:tags, :user, :intensity]) + |> preload([:user, :intensity, tags: :aliases]) |> Repo.one() case featured_image do diff --git a/lib/philomena_web/controllers/api/json/image_controller.ex b/lib/philomena_web/controllers/api/json/image_controller.ex index 6fe81062..3e5f17f5 100644 --- a/lib/philomena_web/controllers/api/json/image_controller.ex +++ b/lib/philomena_web/controllers/api/json/image_controller.ex @@ -20,7 +20,7 @@ defmodule PhilomenaWeb.Api.Json.ImageController do image = Image |> where(id: ^id) - |> preload([:tags, :user, :intensity]) + |> preload([:user, :intensity, tags: :aliases]) |> Repo.one() case image do diff --git a/lib/philomena_web/controllers/api/json/oembed_controller.ex b/lib/philomena_web/controllers/api/json/oembed_controller.ex index eb80eb8b..03269388 100644 --- a/lib/philomena_web/controllers/api/json/oembed_controller.ex +++ b/lib/philomena_web/controllers/api/json/oembed_controller.ex @@ -36,7 +36,7 @@ defmodule PhilomenaWeb.Api.Json.OembedController do defp load_image(id) do Image |> where(id: ^id, hidden_from_users: false) - |> preload([:tags, :user]) + |> preload([:user, tags: :aliases]) |> Repo.one() end diff --git a/lib/philomena_web/controllers/api/json/search/image_controller.ex b/lib/philomena_web/controllers/api/json/search/image_controller.ex index 2aa6e631..9338dc80 100644 --- a/lib/philomena_web/controllers/api/json/search/image_controller.ex +++ b/lib/philomena_web/controllers/api/json/search/image_controller.ex @@ -8,7 +8,7 @@ defmodule PhilomenaWeb.Api.Json.Search.ImageController do import Ecto.Query def index(conn, params) do - queryable = Image |> preload([:tags, :user, :intensity]) + queryable = Image |> preload([:user, :intensity, tags: :aliases]) user = conn.assigns.current_user case ImageLoader.search_string(conn, params["q"]) do diff --git a/lib/philomena_web/controllers/api/rss/watched_controller.ex b/lib/philomena_web/controllers/api/rss/watched_controller.ex index c8937176..d1ab2d5e 100644 --- a/lib/philomena_web/controllers/api/rss/watched_controller.ex +++ b/lib/philomena_web/controllers/api/rss/watched_controller.ex @@ -9,7 +9,7 @@ defmodule PhilomenaWeb.Api.Rss.WatchedController do def index(conn, _params) do {:ok, {images, _tags}} = ImageLoader.search_string(conn, "my:watched") - images = Elasticsearch.search_records(images, preload(Image, :tags)) + images = Elasticsearch.search_records(images, preload(Image, tags: :aliases)) # NB: this is RSS, but using the RSS format causes Phoenix not to # escape HTML diff --git a/lib/philomena_web/controllers/comment_controller.ex b/lib/philomena_web/controllers/comment_controller.ex index 1b5b9b4d..f494fe08 100644 --- a/lib/philomena_web/controllers/comment_controller.ex +++ b/lib/philomena_web/controllers/comment_controller.ex @@ -36,7 +36,7 @@ defmodule PhilomenaWeb.CommentController do conn.assigns.pagination ) |> Elasticsearch.search_records( - preload(Comment, [:deleted_by, image: [:tags], user: [awards: :badge]]) + preload(Comment, [:deleted_by, image: [tags: :aliases], user: [awards: :badge]]) ) rendered = TextileRenderer.render_collection(comments.entries, conn) diff --git a/lib/philomena_web/controllers/commission_controller.ex b/lib/philomena_web/controllers/commission_controller.ex index f0af9432..45a424b3 100644 --- a/lib/philomena_web/controllers/commission_controller.ex +++ b/lib/philomena_web/controllers/commission_controller.ex @@ -70,7 +70,7 @@ defmodule PhilomenaWeb.CommissionController do on: ci.commission_id == c.id, group_by: c.id, order_by: [asc: fragment("random()")], - preload: [user: [awards: :badge], items: [example_image: :tags]] + preload: [user: [awards: :badge], items: [example_image: [tags: :aliases]]] end defp presence(nil), diff --git a/lib/philomena_web/controllers/duplicate_report_controller.ex b/lib/philomena_web/controllers/duplicate_report_controller.ex index f72a7d0b..00ab35bb 100644 --- a/lib/philomena_web/controllers/duplicate_report_controller.ex +++ b/lib/philomena_web/controllers/duplicate_report_controller.ex @@ -26,7 +26,7 @@ defmodule PhilomenaWeb.DuplicateReportController do duplicate_reports = DuplicateReport |> where([d], d.state in ^states) - |> preload([:user, :modifier, image: [:user, :tags], duplicate_of_image: [:user, :tags]]) + |> preload([:user, :modifier, image: [:user, tags: :aliases], duplicate_of_image: [:user, tags: :aliases]]) |> order_by(desc: :created_at) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/fingerprint_profile/source_change_controller.ex b/lib/philomena_web/controllers/fingerprint_profile/source_change_controller.ex index babf3de5..84b057ec 100644 --- a/lib/philomena_web/controllers/fingerprint_profile/source_change_controller.ex +++ b/lib/philomena_web/controllers/fingerprint_profile/source_change_controller.ex @@ -12,7 +12,7 @@ defmodule PhilomenaWeb.FingerprintProfile.SourceChangeController do SourceChange |> where(fingerprint: ^fingerprint) |> order_by(desc: :id) - |> preload([:user, image: [:user, :tags]]) + |> preload([:user, image: [:user, tags: :aliases]]) |> Repo.paginate(conn.assigns.scrivener) render(conn, "index.html", diff --git a/lib/philomena_web/controllers/fingerprint_profile/tag_change_controller.ex b/lib/philomena_web/controllers/fingerprint_profile/tag_change_controller.ex index 0867a76f..ebd1f586 100644 --- a/lib/philomena_web/controllers/fingerprint_profile/tag_change_controller.ex +++ b/lib/philomena_web/controllers/fingerprint_profile/tag_change_controller.ex @@ -12,7 +12,7 @@ defmodule PhilomenaWeb.FingerprintProfile.TagChangeController do TagChange |> where(fingerprint: ^fingerprint) |> added_filter(params) - |> preload([:tag, :user, image: [:user, :tags]]) + |> preload([:tag, :user, image: [:user, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/gallery_controller.ex b/lib/philomena_web/controllers/gallery_controller.ex index 4783f223..94dc32c7 100644 --- a/lib/philomena_web/controllers/gallery_controller.ex +++ b/lib/philomena_web/controllers/gallery_controller.ex @@ -16,7 +16,7 @@ defmodule PhilomenaWeb.GalleryController do plug :load_and_authorize_resource, model: Gallery, except: [:index], - preload: [:creator, thumbnail: :tags] + preload: [:creator, thumbnail: [tags: :aliases]] def index(conn, params) do galleries = @@ -32,7 +32,7 @@ defmodule PhilomenaWeb.GalleryController do }, conn.assigns.pagination ) - |> Elasticsearch.search_records(preload(Gallery, [:creator, thumbnail: :tags])) + |> Elasticsearch.search_records(preload(Gallery, [:creator, thumbnail: [tags: :aliases]])) render(conn, "index.html", title: "Galleries", @@ -62,7 +62,7 @@ defmodule PhilomenaWeb.GalleryController do [images, gallery_prev, gallery_next] = Elasticsearch.msearch_records_with_hits( [images, gallery_prev, gallery_next], - [preload(Image, :tags), preload(Image, :tags), preload(Image, :tags)] + [preload(Image, tags: :aliases), preload(Image, tags: :aliases), preload(Image, tags: :aliases)] ) interactions = Interactions.user_interactions([images, gallery_prev, gallery_next], user) diff --git a/lib/philomena_web/controllers/image/comment/report_controller.ex b/lib/philomena_web/controllers/image/comment/report_controller.ex index bc79cb24..58014da3 100644 --- a/lib/philomena_web/controllers/image/comment/report_controller.ex +++ b/lib/philomena_web/controllers/image/comment/report_controller.ex @@ -18,7 +18,7 @@ defmodule PhilomenaWeb.Image.Comment.ReportController do model: Image, id_name: "image_id", persisted: true, - preload: [:tags] + preload: [tags: :aliases] plug PhilomenaWeb.LoadCommentPlug diff --git a/lib/philomena_web/controllers/image/comment_controller.ex b/lib/philomena_web/controllers/image/comment_controller.ex index 216123fd..5b3d6d38 100644 --- a/lib/philomena_web/controllers/image/comment_controller.ex +++ b/lib/philomena_web/controllers/image/comment_controller.ex @@ -24,7 +24,7 @@ defmodule PhilomenaWeb.Image.CommentController do model: Image, id_name: "image_id", persisted: true, - preload: [:tags] + preload: [tags: :aliases] plug :verify_authorized when action in [:show] plug PhilomenaWeb.FilterForcedUsersPlug when action in [:create, :edit, :update] diff --git a/lib/philomena_web/controllers/image/description_controller.ex b/lib/philomena_web/controllers/image/description_controller.ex index d6ea745a..f09f12fe 100644 --- a/lib/philomena_web/controllers/image/description_controller.ex +++ b/lib/philomena_web/controllers/image/description_controller.ex @@ -12,7 +12,7 @@ defmodule PhilomenaWeb.Image.DescriptionController do model: Image, id_name: "image_id", persisted: true, - preload: [:tags, :user] + preload: [:user, tags: :aliases] def update(conn, %{"image" => image_params}) do image = conn.assigns.image diff --git a/lib/philomena_web/controllers/image/fave_controller.ex b/lib/philomena_web/controllers/image/fave_controller.ex index 2a8a3d77..82e01861 100644 --- a/lib/philomena_web/controllers/image/fave_controller.ex +++ b/lib/philomena_web/controllers/image/fave_controller.ex @@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.FaveController do model: Image, id_name: "image_id", persisted: true, - preload: [:tags] + preload: [tags: :aliases] plug PhilomenaWeb.FilterForcedUsersPlug diff --git a/lib/philomena_web/controllers/image/related_controller.ex b/lib/philomena_web/controllers/image/related_controller.ex index 99353afe..d35578ae 100644 --- a/lib/philomena_web/controllers/image/related_controller.ex +++ b/lib/philomena_web/controllers/image/related_controller.ex @@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.RelatedController do model: Image, id_name: "image_id", persisted: true, - preload: [:tags, :faves] + preload: [:faves, tags: :aliases] def index(conn, _params) do image = conn.assigns.image @@ -60,7 +60,7 @@ defmodule PhilomenaWeb.Image.RelatedController do pagination: %{conn.assigns.image_pagination | page_number: 1} ) - images = Elasticsearch.search_records(images, preload(Image, :tags)) + images = Elasticsearch.search_records(images, preload(Image, tags: :aliases)) interactions = Interactions.user_interactions(images, user) diff --git a/lib/philomena_web/controllers/image/report_controller.ex b/lib/philomena_web/controllers/image/report_controller.ex index 60621bfd..06d084e0 100644 --- a/lib/philomena_web/controllers/image/report_controller.ex +++ b/lib/philomena_web/controllers/image/report_controller.ex @@ -17,7 +17,7 @@ defmodule PhilomenaWeb.Image.ReportController do model: Image, id_name: "image_id", persisted: true, - preload: [:tags] + preload: [tags: :aliases] def new(conn, _params) do image = conn.assigns.image diff --git a/lib/philomena_web/controllers/image/reporting_controller.ex b/lib/philomena_web/controllers/image/reporting_controller.ex index a0c6ba54..67e95114 100644 --- a/lib/philomena_web/controllers/image/reporting_controller.ex +++ b/lib/philomena_web/controllers/image/reporting_controller.ex @@ -11,14 +11,14 @@ defmodule PhilomenaWeb.Image.ReportingController do model: Image, id_name: "image_id", persisted: true, - preload: [:tags] + preload: [tags: :aliases] def show(conn, _params) do image = conn.assigns.image dupe_reports = DuplicateReport - |> preload([:user, :modifier, image: [:user, :tags], duplicate_of_image: [:user, :tags]]) + |> preload([:user, :modifier, image: [:user, tags: :aliases], duplicate_of_image: [:user, tags: :aliases]]) |> where([d], d.image_id == ^image.id or d.duplicate_of_image_id == ^image.id) |> Repo.all() diff --git a/lib/philomena_web/controllers/image/source_change_controller.ex b/lib/philomena_web/controllers/image/source_change_controller.ex index 5e64c465..6f82e55d 100644 --- a/lib/philomena_web/controllers/image/source_change_controller.ex +++ b/lib/philomena_web/controllers/image/source_change_controller.ex @@ -15,7 +15,7 @@ defmodule PhilomenaWeb.Image.SourceChangeController do source_changes = SourceChange |> where(image_id: ^image.id) - |> preload([:user, image: [:user, :tags]]) + |> preload([:user, image: [:user, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/image/source_controller.ex b/lib/philomena_web/controllers/image/source_controller.ex index adfcc7c7..153ba117 100644 --- a/lib/philomena_web/controllers/image/source_controller.ex +++ b/lib/philomena_web/controllers/image/source_controller.ex @@ -17,7 +17,7 @@ defmodule PhilomenaWeb.Image.SourceController do plug PhilomenaWeb.CheckCaptchaPlug plug PhilomenaWeb.UserAttributionPlug plug PhilomenaWeb.CanaryMapPlug, update: :edit_metadata - plug :load_and_authorize_resource, model: Image, id_name: "image_id", preload: [:tags, :user] + plug :load_and_authorize_resource, model: Image, id_name: "image_id", preload: [:user, tags: :aliases] def update(conn, %{"image" => image_params}) do attributes = conn.assigns.attributes diff --git a/lib/philomena_web/controllers/image/tag_change_controller.ex b/lib/philomena_web/controllers/image/tag_change_controller.ex index fe277642..b4b7ddd2 100644 --- a/lib/philomena_web/controllers/image/tag_change_controller.ex +++ b/lib/philomena_web/controllers/image/tag_change_controller.ex @@ -16,7 +16,7 @@ defmodule PhilomenaWeb.Image.TagChangeController do TagChange |> where(image_id: ^image.id) |> added_filter(params) - |> preload([:tag, :user, image: [:user, :tags]]) + |> preload([:tag, :user, image: [:user, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/image/tag_controller.ex b/lib/philomena_web/controllers/image/tag_controller.ex index 836b3b3a..d009ced4 100644 --- a/lib/philomena_web/controllers/image/tag_controller.ex +++ b/lib/philomena_web/controllers/image/tag_controller.ex @@ -19,7 +19,7 @@ defmodule PhilomenaWeb.Image.TagController do plug PhilomenaWeb.CheckCaptchaPlug plug PhilomenaWeb.UserAttributionPlug plug PhilomenaWeb.CanaryMapPlug, update: :edit_metadata - plug :load_and_authorize_resource, model: Image, id_name: "image_id", preload: [:tags, :user] + plug :load_and_authorize_resource, model: Image, id_name: "image_id", preload: [:user, tags: :aliases] def update(conn, %{"image" => image_params}) do attributes = conn.assigns.attributes @@ -58,7 +58,7 @@ defmodule PhilomenaWeb.Image.TagController do image = image - |> Repo.preload(:tags, force: true) + |> Repo.preload([tags: :aliases], [force: true]) changeset = Images.change_image(image) @@ -74,7 +74,7 @@ defmodule PhilomenaWeb.Image.TagController do {:error, :image, changeset, _} -> image = image - |> Repo.preload(:tags, force: true) + |> Repo.preload([tags: :aliases], [force: true]) conn |> put_view(PhilomenaWeb.ImageView) diff --git a/lib/philomena_web/controllers/image/vote_controller.ex b/lib/philomena_web/controllers/image/vote_controller.ex index b3796c86..cf5dfdbc 100644 --- a/lib/philomena_web/controllers/image/vote_controller.ex +++ b/lib/philomena_web/controllers/image/vote_controller.ex @@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.VoteController do model: Image, id_name: "image_id", persisted: true, - preload: [:tags] + preload: [tags: :aliases] plug PhilomenaWeb.FilterForcedUsersPlug diff --git a/lib/philomena_web/controllers/image_controller.ex b/lib/philomena_web/controllers/image_controller.ex index 6ef3b712..de7710eb 100644 --- a/lib/philomena_web/controllers/image_controller.ex +++ b/lib/philomena_web/controllers/image_controller.ex @@ -38,7 +38,7 @@ defmodule PhilomenaWeb.ImageController do def index(conn, _params) do {:ok, {images, _tags}} = ImageLoader.search_string(conn, "created_at.lte:3 minutes ago") - images = Elasticsearch.search_records(images, preload(Image, :tags)) + images = Elasticsearch.search_records(images, preload(Image, tags: :aliases)) interactions = Interactions.user_interactions(images, conn.assigns.current_user) @@ -167,7 +167,7 @@ defmodule PhilomenaWeb.ImageController do [i, _], _ in fragment("SELECT COUNT(*) FROM source_changes s WHERE s.image_id = ?", i.id) ) - |> preload([:tags, :deleter, user: [awards: :badge]]) + |> preload([:deleter, user: [awards: :badge], tags: :aliases]) |> select([i, t, s], {i, t.count, s.count}) |> Repo.one() |> case do diff --git a/lib/philomena_web/controllers/ip_profile/source_change_controller.ex b/lib/philomena_web/controllers/ip_profile/source_change_controller.ex index 46493d7f..7e057de2 100644 --- a/lib/philomena_web/controllers/ip_profile/source_change_controller.ex +++ b/lib/philomena_web/controllers/ip_profile/source_change_controller.ex @@ -14,7 +14,7 @@ defmodule PhilomenaWeb.IpProfile.SourceChangeController do SourceChange |> where(ip: ^ip) |> order_by(desc: :id) - |> preload([:user, image: [:user, :tags]]) + |> preload([:user, image: [:user, tags: :aliases]]) |> Repo.paginate(conn.assigns.scrivener) render(conn, "index.html", diff --git a/lib/philomena_web/controllers/ip_profile/tag_change_controller.ex b/lib/philomena_web/controllers/ip_profile/tag_change_controller.ex index 304aa89a..7ba3a260 100644 --- a/lib/philomena_web/controllers/ip_profile/tag_change_controller.ex +++ b/lib/philomena_web/controllers/ip_profile/tag_change_controller.ex @@ -14,7 +14,7 @@ defmodule PhilomenaWeb.IpProfile.TagChangeController do TagChange |> where(ip: ^ip) |> added_filter(params) - |> preload([:tag, :user, image: [:user, :tags]]) + |> preload([:tag, :user, image: [:user, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/profile/commission/item_controller.ex b/lib/philomena_web/controllers/profile/commission/item_controller.ex index 8bd06f2c..a4f1b7db 100644 --- a/lib/philomena_web/controllers/profile/commission/item_controller.ex +++ b/lib/philomena_web/controllers/profile/commission/item_controller.ex @@ -14,7 +14,7 @@ defmodule PhilomenaWeb.Profile.Commission.ItemController do id_field: "slug", preload: [ :verified_links, - commission: [sheet_image: :tags, user: [awards: :badge], items: [example_image: :tags]] + commission: [sheet_image: [tags: :aliases], user: [awards: :badge], items: [example_image: [tags: :aliases]]] ], persisted: true diff --git a/lib/philomena_web/controllers/profile/commission/report_controller.ex b/lib/philomena_web/controllers/profile/commission/report_controller.ex index 64175f9d..9ca53b9a 100644 --- a/lib/philomena_web/controllers/profile/commission/report_controller.ex +++ b/lib/philomena_web/controllers/profile/commission/report_controller.ex @@ -19,7 +19,7 @@ defmodule PhilomenaWeb.Profile.Commission.ReportController do id_field: "slug", preload: [ :verified_links, - commission: [sheet_image: :tags, user: [awards: :badge], items: [example_image: :tags]] + commission: [sheet_image: [tags: :aliases], user: [awards: :badge], items: [example_image: [tags: :aliases]]] ], persisted: true diff --git a/lib/philomena_web/controllers/profile/commission_controller.ex b/lib/philomena_web/controllers/profile/commission_controller.ex index 528c51e3..60f69a93 100644 --- a/lib/philomena_web/controllers/profile/commission_controller.ex +++ b/lib/philomena_web/controllers/profile/commission_controller.ex @@ -14,7 +14,7 @@ defmodule PhilomenaWeb.Profile.CommissionController do id_field: "slug", preload: [ :verified_links, - commission: [sheet_image: :tags, user: [awards: :badge], items: [example_image: :tags]] + commission: [sheet_image: [tags: :aliases], user: [awards: :badge], items: [example_image: [tags: :aliases]]] ], persisted: true diff --git a/lib/philomena_web/controllers/profile/source_change_controller.ex b/lib/philomena_web/controllers/profile/source_change_controller.ex index 85bc4c39..9a0fb595 100644 --- a/lib/philomena_web/controllers/profile/source_change_controller.ex +++ b/lib/philomena_web/controllers/profile/source_change_controller.ex @@ -25,7 +25,7 @@ defmodule PhilomenaWeb.Profile.SourceChangeController do [sc, i], sc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true) ) - |> preload([:user, image: [:user, :tags]]) + |> preload([:user, image: [:user, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/profile/tag_change_controller.ex b/lib/philomena_web/controllers/profile/tag_change_controller.ex index 2efd2fd4..0c58adc4 100644 --- a/lib/philomena_web/controllers/profile/tag_change_controller.ex +++ b/lib/philomena_web/controllers/profile/tag_change_controller.ex @@ -21,7 +21,7 @@ defmodule PhilomenaWeb.Profile.TagChangeController do tc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true) ) |> added_filter(params) - |> preload([:tag, :user, image: [:user, :tags]]) + |> preload([:tag, :user, image: [:user, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/profile_controller.ex b/lib/philomena_web/controllers/profile_controller.ex index 0715e2b7..2f721fd3 100644 --- a/lib/philomena_web/controllers/profile_controller.ex +++ b/lib/philomena_web/controllers/profile_controller.ex @@ -28,7 +28,7 @@ defmodule PhilomenaWeb.ProfileController do awards: [:badge, :awarded_by], public_links: :tag, verified_links: :tag, - commission: [sheet_image: :tags, items: [example_image: :tags]] + commission: [sheet_image: [tags: :aliases], items: [example_image: [tags: :aliases]]] ] plug :set_admin_metadata @@ -118,10 +118,10 @@ defmodule PhilomenaWeb.ProfileController do Elasticsearch.msearch_records( [recent_uploads, recent_faves, recent_artwork, recent_comments, recent_posts], [ - preload(Image, :tags), - preload(Image, :tags), - preload(Image, :tags), - preload(Comment, user: [awards: :badge], image: :tags), + preload(Image, tags: :aliases), + preload(Image, tags: :aliases), + preload(Image, tags: :aliases), + preload(Comment, user: [awards: :badge], image: [tags: :aliases]), preload(Post, user: [awards: :badge], topic: :forum) ] ) @@ -143,7 +143,7 @@ defmodule PhilomenaWeb.ProfileController do recent_galleries = Gallery |> where(creator_id: ^user.id) - |> preload([:creator, thumbnail: :tags]) + |> preload([:creator, thumbnail: [tags: :aliases]]) |> limit(4) |> Repo.all() diff --git a/lib/philomena_web/controllers/search_controller.ex b/lib/philomena_web/controllers/search_controller.ex index afc0803f..2bfbc7f9 100644 --- a/lib/philomena_web/controllers/search_controller.ex +++ b/lib/philomena_web/controllers/search_controller.ex @@ -12,7 +12,7 @@ defmodule PhilomenaWeb.SearchController do case ImageLoader.search_string(conn, params["q"]) do {:ok, {images, tags}} -> - images = search_function(custom_ordering?(conn)).(images, preload(Image, :tags)) + images = search_function(custom_ordering?(conn)).(images, preload(Image, tags: :aliases)) interactions = Interactions.user_interactions(images, user) conn diff --git a/lib/philomena_web/controllers/tag/tag_change_controller.ex b/lib/philomena_web/controllers/tag/tag_change_controller.ex index 7de1a0fb..69adcc2e 100644 --- a/lib/philomena_web/controllers/tag/tag_change_controller.ex +++ b/lib/philomena_web/controllers/tag/tag_change_controller.ex @@ -16,7 +16,7 @@ defmodule PhilomenaWeb.Tag.TagChangeController do TagChange |> where(tag_id: ^tag.id) |> added_filter(params) - |> preload([:tag, :user, image: [:user, :tags]]) + |> preload([:tag, :user, image: [:user, tags: :aliases]]) |> order_by(desc: :id) |> Repo.paginate(conn.assigns.scrivener) diff --git a/lib/philomena_web/controllers/tag_controller.ex b/lib/philomena_web/controllers/tag_controller.ex index 8ddff443..2d527a38 100644 --- a/lib/philomena_web/controllers/tag_controller.ex +++ b/lib/philomena_web/controllers/tag_controller.ex @@ -57,7 +57,7 @@ defmodule PhilomenaWeb.TagController do {images, _tags} = ImageLoader.query(conn, %{term: %{"namespaced_tags.name" => tag.name}}) - images = Elasticsearch.search_records(images, preload(Image, :tags)) + images = Elasticsearch.search_records(images, preload(Image, tags: :aliases)) interactions = Interactions.user_interactions(images, user) diff --git a/lib/philomena_web/image_reverse.ex b/lib/philomena_web/image_reverse.ex index a41898f3..02dc9d59 100644 --- a/lib/philomena_web/image_reverse.ex +++ b/lib/philomena_web/image_reverse.ex @@ -20,7 +20,7 @@ defmodule PhilomenaWeb.ImageReverse do dist = normalize_dist(image_params) DuplicateReports.duplicates_of(intensities, aspect, dist, dist) - |> preload([:tags, :user, :intensity]) + |> preload([:user, :intensity, [tags: :aliases]]) |> Repo.all() end end diff --git a/lib/philomena_web/textile_renderer.ex b/lib/philomena_web/textile_renderer.ex index 193b3ba7..00e111c2 100644 --- a/lib/philomena_web/textile_renderer.ex +++ b/lib/philomena_web/textile_renderer.ex @@ -121,7 +121,7 @@ defmodule PhilomenaWeb.TextileRenderer do Image |> where([i], i.id in ^ids) |> where([i], i.hidden_from_users == false) - |> preload(:tags) + |> preload(tags: :aliases) |> Repo.all() |> Map.new(&{&1.id, &1}) end diff --git a/lib/philomena_web/views/image_view.ex b/lib/philomena_web/views/image_view.ex index af70585f..f91c6ed4 100644 --- a/lib/philomena_web/views/image_view.ex +++ b/lib/philomena_web/views/image_view.ex @@ -129,7 +129,7 @@ defmodule PhilomenaWeb.ImageView do [ image_id: image.id, image_tags: Jason.encode!(Enum.map(image.tags, & &1.id)), - image_tag_aliases: image.tag_list_plus_alias_cache, + image_tag_aliases: image.tags |> Enum.flat_map(&([&1] ++ &1.aliases)) |> Enum.map_join(", ", &(&1.name)), tag_count: length(image.tags), score: image.score, faves: image.faves_count, @@ -222,7 +222,7 @@ defmodule PhilomenaWeb.ImageView do def image_filter_data(image) do %{ id: image.id, - "namespaced_tags.name": String.split(image.tag_list_plus_alias_cache || "", ", "), + "namespaced_tags.name": image.tags |> Enum.flat_map(&([&1] ++ &1.aliases)) |> Enum.map_join(", ", &(&1.name)), tag_count: length(image.tags), score: image.score, faves: image.faves_count,