no more need for preloading tags

This commit is contained in:
byte[] 2020-08-16 06:03:33 -04:00
parent fdda89500b
commit 127aa542f4
17 changed files with 24 additions and 24 deletions

View file

@ -54,7 +54,7 @@ defmodule PhilomenaWeb.ActivityController do
sort: %{posted_at: :desc} sort: %{posted_at: :desc}
}, },
%{page_number: 1, page_size: 6}, %{page_number: 1, page_size: 6},
Comment |> preload([:user, image: [:tags]]) Comment |> preload([:user, :image])
) )
comment_images = Enum.map(comments, & &1.image) comment_images = Enum.map(comments, & &1.image)
@ -77,7 +77,6 @@ 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])
|> Repo.one() |> Repo.one()
streams = streams =

View file

@ -27,7 +27,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], duplicate_of_image: [:user]])
|> order_by(desc: :created_at) |> order_by(desc: :created_at)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -13,7 +13,7 @@ defmodule PhilomenaWeb.FingerprintProfile.SourceChangeController do
SourceChange SourceChange
|> where(fingerprint: ^fingerprint) |> where(fingerprint: ^fingerprint)
|> order_by(desc: :created_at) |> order_by(desc: :created_at)
|> preload([:user, image: [:user, :tags]]) |> preload([:user, image: [:user]])
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)
spoilers = spoilers =

View file

@ -13,7 +13,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]])
|> order_by(desc: :created_at) |> order_by(desc: :created_at)
|> 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]
def index(conn, params) do def index(conn, params) do
galleries = galleries =
@ -31,7 +31,7 @@ defmodule PhilomenaWeb.GalleryController do
sort: parse_sort(params) sort: parse_sort(params)
}, },
conn.assigns.pagination, conn.assigns.pagination,
Gallery |> preload([:creator, thumbnail: :tags]) Gallery |> preload([:creator, :thumbnail])
) )
spoilers = spoilers =

View file

@ -23,8 +23,7 @@ defmodule PhilomenaWeb.Image.CommentController do
plug :load_and_authorize_resource, plug :load_and_authorize_resource,
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true
preload: [:tags]
plug :verify_authorized when action in [:show] plug :verify_authorized when action in [:show]

View file

@ -11,15 +11,14 @@ defmodule PhilomenaWeb.Image.ReportingController do
plug :load_and_authorize_resource, plug :load_and_authorize_resource,
model: Image, model: Image,
id_name: "image_id", id_name: "image_id",
persisted: true, persisted: true
preload: [:tags]
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], duplicate_of_image: [:user]])
|> 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

@ -16,7 +16,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]])
|> order_by(desc: :created_at) |> order_by(desc: :created_at)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -17,7 +17,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]])
|> order_by(desc: :created_at) |> order_by(desc: :created_at)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -15,7 +15,7 @@ defmodule PhilomenaWeb.IpProfile.SourceChangeController do
SourceChange SourceChange
|> where(ip: ^ip) |> where(ip: ^ip)
|> order_by(desc: :created_at) |> order_by(desc: :created_at)
|> preload([:user, image: [:user, :tags]]) |> preload([:user, image: [:user]])
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)
spoilers = spoilers =

View file

@ -15,7 +15,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]])
|> order_by(desc: :created_at) |> order_by(desc: :created_at)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -26,7 +26,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]])
|> order_by(desc: :created_at) |> order_by(desc: :created_at)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -22,7 +22,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]])
|> order_by(desc: :created_at) |> order_by(desc: :created_at)
|> 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, items: :example_image]
] ]
plug :set_admin_metadata plug :set_admin_metadata
@ -93,7 +93,7 @@ defmodule PhilomenaWeb.ProfileController do
sort: %{posted_at: :desc} sort: %{posted_at: :desc}
}, },
%{page_size: 3}, %{page_size: 3},
Comment |> preload(user: [awards: :badge], image: :tags) Comment |> preload([:image, user: [awards: :badge]])
) )
|> Enum.filter(&Canada.Can.can?(current_user, :show, &1.image)) |> Enum.filter(&Canada.Can.can?(current_user, :show, &1.image))
@ -132,7 +132,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])
|> limit(4) |> limit(4)
|> Repo.all() |> Repo.all()

View file

@ -17,7 +17,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]])
|> order_by(desc: :created_at) |> order_by(desc: :created_at)
|> Repo.paginate(conn.assigns.scrivener) |> Repo.paginate(conn.assigns.scrivener)

View file

@ -20,7 +20,7 @@ defmodule PhilomenaWeb.ImageLoader do
def query(conn, body, options \\ []) do def query(conn, body, options \\ []) do
pagination = Keyword.get(options, :pagination, conn.assigns.image_pagination) pagination = Keyword.get(options, :pagination, conn.assigns.image_pagination)
queryable = Keyword.get(options, :queryable, Image |> preload(:tags)) queryable = Keyword.get(options, :queryable, Image)
sorts = Keyword.get(options, :sorts, &ImageSorter.parse_sort(conn.params, &1)) sorts = Keyword.get(options, :sorts, &ImageSorter.parse_sort(conn.params, &1))
tags = tags =

View file

@ -7,11 +7,14 @@ defmodule PhilomenaWeb.ImageView do
def show_vote_counts?(_user), do: true def show_vote_counts?(_user), do: true
def title_text(image) do def title_text(image) do
tags = Tag.display_order(image.tags) |> Enum.map_join(", ", & &1.name) tags = truncate(image.tag_list_cache)
"Size: #{image.image_width}x#{image.image_height} | Tagged: #{tags}" "Size: #{image.image_width}x#{image.image_height} | Tagged: #{tags}"
end end
def truncate(<<string::binary-size(1024), _rest::binary>>), do: string <> "..."
def truncate(string), do: string
# this is a bit ridiculous # this is a bit ridiculous
def render_intent(_conn, %{thumbnails_generated: false}, _size), do: :not_rendered def render_intent(_conn, %{thumbnails_generated: false}, _size), do: :not_rendered