Fixes batch tagging messing with complex spoilers (#49)

This commit is contained in:
parasprite 2020-12-03 13:23:32 -06:00 committed by GitHub
parent 7803050666
commit 39fe2cbd55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 59 additions and 59 deletions

View file

@ -20,12 +20,12 @@ defmodule Philomena.Polymorphic do
} }
@preloads %{ @preloads %{
"Comment" => [:user, image: :tags], "Comment" => [:user, image: [tags: :aliases]],
"Commission" => [:user], "Commission" => [:user],
"Conversation" => [:from, :to], "Conversation" => [:from, :to],
"DnpEntry" => [:requesting_user], "DnpEntry" => [:requesting_user],
"Gallery" => [:creator], "Gallery" => [:creator],
"Image" => [:user, :tags], "Image" => [:user, tags: :aliases],
"Post" => [:user, topic: :forum], "Post" => [:user, topic: :forum],
"Topic" => [:forum, :user], "Topic" => [:forum, :user],
"Report" => [:user] "Report" => [:user]

View file

@ -76,7 +76,7 @@ defmodule PhilomenaWeb.ActivityController do
|> filter_hidden(user, conn.params["hidden"]) |> filter_hidden(user, conn.params["hidden"])
|> order_by([i, f], desc: f.created_at) |> order_by([i, f], desc: f.created_at)
|> limit(1) |> limit(1)
|> preload([:tags]) |> preload([tags: :aliases])
|> Repo.one() |> Repo.one()
streams = streams =
@ -144,7 +144,7 @@ defmodule PhilomenaWeb.ActivityController do
responses = responses =
Elasticsearch.msearch_records( Elasticsearch.msearch_records(
[images, top_scoring, comments], [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] responses ++ [nil]
@ -154,10 +154,10 @@ defmodule PhilomenaWeb.ActivityController do
Elasticsearch.msearch_records( Elasticsearch.msearch_records(
[images, top_scoring, comments, watched], [images, top_scoring, comments, watched],
[ [
preload(Image, :tags), preload(Image, tags: :aliases),
preload(Image, :tags), preload(Image, tags: :aliases),
preload(Comment, [:user, image: :tags]), preload(Comment, [:user, image: [tags: :aliases]]),
preload(Image, :tags) preload(Image, tags: :aliases)
] ]
) )
end end

View file

@ -15,7 +15,7 @@ defmodule PhilomenaWeb.Api.Json.Image.FeaturedController do
|> join(:inner, [i], f in ImageFeature, on: [image_id: i.id]) |> join(:inner, [i], f in ImageFeature, on: [image_id: i.id])
|> order_by([_i, f], desc: f.created_at) |> order_by([_i, f], desc: f.created_at)
|> limit(1) |> limit(1)
|> preload([:tags, :user, :intensity]) |> preload([:user, :intensity, tags: :aliases])
|> Repo.one() |> Repo.one()
case featured_image do case featured_image do

View file

@ -20,7 +20,7 @@ defmodule PhilomenaWeb.Api.Json.ImageController do
image = image =
Image Image
|> where(id: ^id) |> where(id: ^id)
|> preload([:tags, :user, :intensity]) |> preload([:user, :intensity, tags: :aliases])
|> Repo.one() |> Repo.one()
case image do case image do

View file

@ -36,7 +36,7 @@ defmodule PhilomenaWeb.Api.Json.OembedController do
defp load_image(id) do defp load_image(id) do
Image Image
|> where(id: ^id, hidden_from_users: false) |> where(id: ^id, hidden_from_users: false)
|> preload([:tags, :user]) |> preload([:user, tags: :aliases])
|> Repo.one() |> Repo.one()
end end

View file

@ -8,7 +8,7 @@ defmodule PhilomenaWeb.Api.Json.Search.ImageController do
import Ecto.Query import Ecto.Query
def index(conn, params) do def index(conn, params) do
queryable = Image |> preload([:tags, :user, :intensity]) queryable = Image |> preload([:user, :intensity, tags: :aliases])
user = conn.assigns.current_user user = conn.assigns.current_user
case ImageLoader.search_string(conn, params["q"]) do case ImageLoader.search_string(conn, params["q"]) do

View file

@ -9,7 +9,7 @@ defmodule PhilomenaWeb.Api.Rss.WatchedController do
def index(conn, _params) do def index(conn, _params) do
{:ok, {images, _tags}} = ImageLoader.search_string(conn, "my:watched") {: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 # NB: this is RSS, but using the RSS format causes Phoenix not to
# escape HTML # escape HTML

View file

@ -36,7 +36,7 @@ defmodule PhilomenaWeb.CommentController do
conn.assigns.pagination conn.assigns.pagination
) )
|> Elasticsearch.search_records( |> 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) rendered = TextileRenderer.render_collection(comments.entries, conn)

View file

@ -70,7 +70,7 @@ defmodule PhilomenaWeb.CommissionController do
on: ci.commission_id == c.id, on: ci.commission_id == c.id,
group_by: c.id, group_by: c.id,
order_by: [asc: fragment("random()")], order_by: [asc: fragment("random()")],
preload: [user: [awards: :badge], items: [example_image: :tags]] preload: [user: [awards: :badge], items: [example_image: [tags: :aliases]]]
end end
defp presence(nil), defp presence(nil),

View file

@ -26,7 +26,7 @@ defmodule PhilomenaWeb.DuplicateReportController do
duplicate_reports = duplicate_reports =
DuplicateReport DuplicateReport
|> where([d], d.state in ^states) |> 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) |> order_by(desc: :created_at)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -12,7 +12,7 @@ defmodule PhilomenaWeb.FingerprintProfile.SourceChangeController do
SourceChange SourceChange
|> where(fingerprint: ^fingerprint) |> where(fingerprint: ^fingerprint)
|> order_by(desc: :id) |> order_by(desc: :id)
|> preload([:user, image: [:user, :tags]]) |> preload([:user, image: [:user, tags: :aliases]])
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)
render(conn, "index.html", render(conn, "index.html",

View file

@ -12,7 +12,7 @@ defmodule PhilomenaWeb.FingerprintProfile.TagChangeController do
TagChange TagChange
|> where(fingerprint: ^fingerprint) |> where(fingerprint: ^fingerprint)
|> added_filter(params) |> added_filter(params)
|> preload([:tag, :user, image: [:user, :tags]]) |> preload([:tag, :user, image: [:user, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -16,7 +16,7 @@ defmodule PhilomenaWeb.GalleryController do
plug :load_and_authorize_resource, plug :load_and_authorize_resource,
model: Gallery, model: Gallery,
except: [:index], except: [:index],
preload: [:creator, thumbnail: :tags] preload: [:creator, thumbnail: [tags: :aliases]]
def index(conn, params) do def index(conn, params) do
galleries = galleries =
@ -32,7 +32,7 @@ defmodule PhilomenaWeb.GalleryController do
}, },
conn.assigns.pagination conn.assigns.pagination
) )
|> Elasticsearch.search_records(preload(Gallery, [:creator, thumbnail: :tags])) |> Elasticsearch.search_records(preload(Gallery, [:creator, thumbnail: [tags: :aliases]]))
render(conn, "index.html", render(conn, "index.html",
title: "Galleries", title: "Galleries",
@ -62,7 +62,7 @@ defmodule PhilomenaWeb.GalleryController do
[images, gallery_prev, gallery_next] = [images, gallery_prev, gallery_next] =
Elasticsearch.msearch_records_with_hits( Elasticsearch.msearch_records_with_hits(
[images, gallery_prev, gallery_next], [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) interactions = Interactions.user_interactions([images, gallery_prev, gallery_next], user)

View file

@ -18,7 +18,7 @@ defmodule PhilomenaWeb.Image.Comment.ReportController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [:tags] preload: [tags: :aliases]
plug PhilomenaWeb.LoadCommentPlug plug PhilomenaWeb.LoadCommentPlug

View file

@ -24,7 +24,7 @@ defmodule PhilomenaWeb.Image.CommentController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [:tags] preload: [tags: :aliases]
plug :verify_authorized when action in [:show] plug :verify_authorized when action in [:show]
plug PhilomenaWeb.FilterForcedUsersPlug when action in [:create, :edit, :update] plug PhilomenaWeb.FilterForcedUsersPlug when action in [:create, :edit, :update]

View file

@ -12,7 +12,7 @@ defmodule PhilomenaWeb.Image.DescriptionController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [:tags, :user] preload: [:user, tags: :aliases]
def update(conn, %{"image" => image_params}) do def update(conn, %{"image" => image_params}) do
image = conn.assigns.image image = conn.assigns.image

View file

@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.FaveController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [:tags] preload: [tags: :aliases]
plug PhilomenaWeb.FilterForcedUsersPlug plug PhilomenaWeb.FilterForcedUsersPlug

View file

@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.RelatedController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [:tags, :faves] preload: [:faves, tags: :aliases]
def index(conn, _params) do def index(conn, _params) do
image = conn.assigns.image image = conn.assigns.image
@ -60,7 +60,7 @@ defmodule PhilomenaWeb.Image.RelatedController do
pagination: %{conn.assigns.image_pagination | page_number: 1} 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) interactions = Interactions.user_interactions(images, user)

View file

@ -17,7 +17,7 @@ defmodule PhilomenaWeb.Image.ReportController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [:tags] preload: [tags: :aliases]
def new(conn, _params) do def new(conn, _params) do
image = conn.assigns.image image = conn.assigns.image

View file

@ -11,14 +11,14 @@ defmodule PhilomenaWeb.Image.ReportingController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [:tags] preload: [tags: :aliases]
def show(conn, _params) do def show(conn, _params) do
image = conn.assigns.image image = conn.assigns.image
dupe_reports = dupe_reports =
DuplicateReport 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) |> where([d], d.image_id == ^image.id or d.duplicate_of_image_id == ^image.id)
|> Repo.all() |> Repo.all()

View file

@ -15,7 +15,7 @@ defmodule PhilomenaWeb.Image.SourceChangeController do
source_changes = source_changes =
SourceChange SourceChange
|> where(image_id: ^image.id) |> where(image_id: ^image.id)
|> preload([:user, image: [:user, :tags]]) |> preload([:user, image: [:user, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -17,7 +17,7 @@ defmodule PhilomenaWeb.Image.SourceController do
plug PhilomenaWeb.CheckCaptchaPlug plug PhilomenaWeb.CheckCaptchaPlug
plug PhilomenaWeb.UserAttributionPlug plug PhilomenaWeb.UserAttributionPlug
plug PhilomenaWeb.CanaryMapPlug, update: :edit_metadata 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 def update(conn, %{"image" => image_params}) do
attributes = conn.assigns.attributes attributes = conn.assigns.attributes

View file

@ -16,7 +16,7 @@ defmodule PhilomenaWeb.Image.TagChangeController do
TagChange TagChange
|> where(image_id: ^image.id) |> where(image_id: ^image.id)
|> added_filter(params) |> added_filter(params)
|> preload([:tag, :user, image: [:user, :tags]]) |> preload([:tag, :user, image: [:user, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -19,7 +19,7 @@ defmodule PhilomenaWeb.Image.TagController do
plug PhilomenaWeb.CheckCaptchaPlug plug PhilomenaWeb.CheckCaptchaPlug
plug PhilomenaWeb.UserAttributionPlug plug PhilomenaWeb.UserAttributionPlug
plug PhilomenaWeb.CanaryMapPlug, update: :edit_metadata 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 def update(conn, %{"image" => image_params}) do
attributes = conn.assigns.attributes attributes = conn.assigns.attributes
@ -58,7 +58,7 @@ defmodule PhilomenaWeb.Image.TagController do
image = image =
image image
|> Repo.preload(:tags, force: true) |> Repo.preload([tags: :aliases], [force: true])
changeset = Images.change_image(image) changeset = Images.change_image(image)
@ -74,7 +74,7 @@ defmodule PhilomenaWeb.Image.TagController do
{:error, :image, changeset, _} -> {:error, :image, changeset, _} ->
image = image =
image image
|> Repo.preload(:tags, force: true) |> Repo.preload([tags: :aliases], [force: true])
conn conn
|> put_view(PhilomenaWeb.ImageView) |> put_view(PhilomenaWeb.ImageView)

View file

@ -13,7 +13,7 @@ defmodule PhilomenaWeb.Image.VoteController do
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true,
preload: [:tags] preload: [tags: :aliases]
plug PhilomenaWeb.FilterForcedUsersPlug plug PhilomenaWeb.FilterForcedUsersPlug

View file

@ -38,7 +38,7 @@ defmodule PhilomenaWeb.ImageController do
def index(conn, _params) do def index(conn, _params) do
{:ok, {images, _tags}} = ImageLoader.search_string(conn, "created_at.lte:3 minutes ago") {: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) interactions = Interactions.user_interactions(images, conn.assigns.current_user)
@ -167,7 +167,7 @@ defmodule PhilomenaWeb.ImageController do
[i, _], [i, _],
_ in fragment("SELECT COUNT(*) FROM source_changes s WHERE s.image_id = ?", i.id) _ 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}) |> select([i, t, s], {i, t.count, s.count})
|> Repo.one() |> Repo.one()
|> case do |> case do

View file

@ -14,7 +14,7 @@ defmodule PhilomenaWeb.IpProfile.SourceChangeController do
SourceChange SourceChange
|> where(ip: ^ip) |> where(ip: ^ip)
|> order_by(desc: :id) |> order_by(desc: :id)
|> preload([:user, image: [:user, :tags]]) |> preload([:user, image: [:user, tags: :aliases]])
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)
render(conn, "index.html", render(conn, "index.html",

View file

@ -14,7 +14,7 @@ defmodule PhilomenaWeb.IpProfile.TagChangeController do
TagChange TagChange
|> where(ip: ^ip) |> where(ip: ^ip)
|> added_filter(params) |> added_filter(params)
|> preload([:tag, :user, image: [:user, :tags]]) |> preload([:tag, :user, image: [:user, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -14,7 +14,7 @@ defmodule PhilomenaWeb.Profile.Commission.ItemController do
id_field: "slug", id_field: "slug",
preload: [ preload: [
:verified_links, :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 persisted: true

View file

@ -19,7 +19,7 @@ defmodule PhilomenaWeb.Profile.Commission.ReportController do
id_field: "slug", id_field: "slug",
preload: [ preload: [
:verified_links, :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 persisted: true

View file

@ -14,7 +14,7 @@ defmodule PhilomenaWeb.Profile.CommissionController do
id_field: "slug", id_field: "slug",
preload: [ preload: [
:verified_links, :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 persisted: true

View file

@ -25,7 +25,7 @@ defmodule PhilomenaWeb.Profile.SourceChangeController do
[sc, i], [sc, i],
sc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true) 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) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -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) tc.user_id == ^user.id and not (i.user_id == ^user.id and i.anonymous == true)
) )
|> added_filter(params) |> added_filter(params)
|> preload([:tag, :user, image: [:user, :tags]]) |> preload([:tag, :user, image: [:user, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -28,7 +28,7 @@ defmodule PhilomenaWeb.ProfileController do
awards: [:badge, :awarded_by], awards: [:badge, :awarded_by],
public_links: :tag, public_links: :tag,
verified_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 plug :set_admin_metadata
@ -118,10 +118,10 @@ defmodule PhilomenaWeb.ProfileController do
Elasticsearch.msearch_records( Elasticsearch.msearch_records(
[recent_uploads, recent_faves, recent_artwork, recent_comments, recent_posts], [recent_uploads, recent_faves, recent_artwork, recent_comments, recent_posts],
[ [
preload(Image, :tags), preload(Image, tags: :aliases),
preload(Image, :tags), preload(Image, tags: :aliases),
preload(Image, :tags), preload(Image, tags: :aliases),
preload(Comment, user: [awards: :badge], image: :tags), preload(Comment, user: [awards: :badge], image: [tags: :aliases]),
preload(Post, user: [awards: :badge], topic: :forum) preload(Post, user: [awards: :badge], topic: :forum)
] ]
) )
@ -143,7 +143,7 @@ defmodule PhilomenaWeb.ProfileController do
recent_galleries = recent_galleries =
Gallery Gallery
|> where(creator_id: ^user.id) |> where(creator_id: ^user.id)
|> preload([:creator, thumbnail: :tags]) |> preload([:creator, thumbnail: [tags: :aliases]])
|> limit(4) |> limit(4)
|> Repo.all() |> Repo.all()

View file

@ -12,7 +12,7 @@ defmodule PhilomenaWeb.SearchController do
case ImageLoader.search_string(conn, params["q"]) do case ImageLoader.search_string(conn, params["q"]) do
{:ok, {images, tags}} -> {: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) interactions = Interactions.user_interactions(images, user)
conn conn

View file

@ -16,7 +16,7 @@ defmodule PhilomenaWeb.Tag.TagChangeController do
TagChange TagChange
|> where(tag_id: ^tag.id) |> where(tag_id: ^tag.id)
|> added_filter(params) |> added_filter(params)
|> preload([:tag, :user, image: [:user, :tags]]) |> preload([:tag, :user, image: [:user, tags: :aliases]])
|> order_by(desc: :id) |> order_by(desc: :id)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -57,7 +57,7 @@ defmodule PhilomenaWeb.TagController do
{images, _tags} = ImageLoader.query(conn, %{term: %{"namespaced_tags.name" => tag.name}}) {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) interactions = Interactions.user_interactions(images, user)

View file

@ -20,7 +20,7 @@ defmodule PhilomenaWeb.ImageReverse do
dist = normalize_dist(image_params) dist = normalize_dist(image_params)
DuplicateReports.duplicates_of(intensities, aspect, dist, dist) DuplicateReports.duplicates_of(intensities, aspect, dist, dist)
|> preload([:tags, :user, :intensity]) |> preload([:user, :intensity, [tags: :aliases]])
|> Repo.all() |> Repo.all()
end end
end end

View file

@ -121,7 +121,7 @@ defmodule PhilomenaWeb.TextileRenderer do
Image Image
|> where([i], i.id in ^ids) |> where([i], i.id in ^ids)
|> where([i], i.hidden_from_users == false) |> where([i], i.hidden_from_users == false)
|> preload(:tags) |> preload(tags: :aliases)
|> Repo.all() |> Repo.all()
|> Map.new(&{&1.id, &1}) |> Map.new(&{&1.id, &1})
end end

View file

@ -129,7 +129,7 @@ defmodule PhilomenaWeb.ImageView do
[ [
image_id: image.id, image_id: image.id,
image_tags: Jason.encode!(Enum.map(image.tags, & &1.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), tag_count: length(image.tags),
score: image.score, score: image.score,
faves: image.faves_count, faves: image.faves_count,
@ -222,7 +222,7 @@ defmodule PhilomenaWeb.ImageView do
def image_filter_data(image) do def image_filter_data(image) do
%{ %{
id: image.id, 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), tag_count: length(image.tags),
score: image.score, score: image.score,
faves: image.faves_count, faves: image.faves_count,