mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
no more need for preloading tags
This commit is contained in:
parent
fdda89500b
commit
127aa542f4
17 changed files with 24 additions and 24 deletions
|
@ -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 =
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue