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}
},
%{page_number: 1, page_size: 6},
Comment |> preload([:user, image: [:tags]])
Comment |> preload([:user, :image])
)
comment_images = Enum.map(comments, & &1.image)
@ -77,7 +77,6 @@ defmodule PhilomenaWeb.ActivityController do
|> filter_hidden(user, conn.params["hidden"])
|> order_by([i, f], desc: f.created_at)
|> limit(1)
|> preload([:tags])
|> Repo.one()
streams =

View file

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

View file

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

View file

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

View file

@ -16,7 +16,7 @@ defmodule PhilomenaWeb.GalleryController do
plug :load_and_authorize_resource,
model: Gallery,
except: [:index],
preload: [:creator, thumbnail: :tags]
preload: [:creator, :thumbnail]
def index(conn, params) do
galleries =
@ -31,7 +31,7 @@ defmodule PhilomenaWeb.GalleryController do
sort: parse_sort(params)
},
conn.assigns.pagination,
Gallery |> preload([:creator, thumbnail: :tags])
Gallery |> preload([:creator, :thumbnail])
)
spoilers =

View file

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

View file

@ -11,15 +11,14 @@ defmodule PhilomenaWeb.Image.ReportingController do
plug :load_and_authorize_resource,
model: Image,
id_name: "image_id",
persisted: true,
preload: [:tags]
persisted: true
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], duplicate_of_image: [:user]])
|> where([d], d.image_id == ^image.id or d.duplicate_of_image_id == ^image.id)
|> Repo.all()

View file

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

View file

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

View file

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

View file

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

View file

@ -26,7 +26,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]])
|> order_by(desc: :created_at)
|> 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)
)
|> added_filter(params)
|> preload([:tag, :user, image: [:user, :tags]])
|> preload([:tag, :user, image: [:user]])
|> order_by(desc: :created_at)
|> Repo.paginate(conn.assigns.scrivener)

View file

@ -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, items: :example_image]
]
plug :set_admin_metadata
@ -93,7 +93,7 @@ defmodule PhilomenaWeb.ProfileController do
sort: %{posted_at: :desc}
},
%{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))
@ -132,7 +132,7 @@ defmodule PhilomenaWeb.ProfileController do
recent_galleries =
Gallery
|> where(creator_id: ^user.id)
|> preload([:creator, thumbnail: :tags])
|> preload([:creator, :thumbnail])
|> limit(4)
|> Repo.all()

View file

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

View file

@ -20,7 +20,7 @@ defmodule PhilomenaWeb.ImageLoader do
def query(conn, body, options \\ []) do
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))
tags =

View file

@ -7,11 +7,14 @@ defmodule PhilomenaWeb.ImageView do
def show_vote_counts?(_user), do: true
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}"
end
def truncate(<<string::binary-size(1024), _rest::binary>>), do: string <> "..."
def truncate(string), do: string
# this is a bit ridiculous
def render_intent(_conn, %{thumbnails_generated: false}, _size), do: :not_rendered