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}
|
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 =
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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 =
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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 =
|
||||||
|
|
|
@ -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]
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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 =
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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 =
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue