Revert "more aggressive preloading"

This reverts commit 556cd39afd.
This commit is contained in:
byte[] 2019-12-22 22:13:36 -05:00
parent 25d867a213
commit 991cab61bf
5 changed files with 11 additions and 34 deletions

View file

@ -101,21 +101,17 @@ defmodule Philomena.Textile.Renderer do
end
defp find_images(text_segments) do
text_segments
|> Enum.flat_map(fn t ->
Regex.scan(~r|>>(\d+)|, t, capture: :all_but_first)
|> Enum.map(fn [first] -> String.to_integer(first) end)
end)
|> find_image_ids()
end
image_ids =
text_segments
|> Enum.flat_map(fn t ->
Regex.scan(~r|>>(\d+)|, t, capture: :all_but_first)
|> Enum.map(fn [first] -> String.to_integer(first) end)
end)
defp find_image_ids([]), do: %{}
defp find_image_ids(image_ids) do
Image
|> where([i], i.id in ^image_ids)
|> where([i], i.hidden_from_users == false)
|> join(:left, [i], _ in assoc(i, :tags))
|> preload([_i, t], tags: t)
|> preload(:tags)
|> Repo.all()
|> Map.new(fn image -> {image.id, image} end)
end

View file

@ -3,15 +3,6 @@ defmodule PhilomenaWeb.CommentLoader do
alias Philomena.Repo
import Ecto.Query
# More aggressive preloading skipped due to overhead
# from scrivener:
#
# |> join(:left, [c], _ in assoc(c, :image))
# |> join(:left, [c, _i], _ in assoc(c, :user))
# |> join(:left, [_c, _i, u], _ in assoc(u, :awards))
# |> join(:left, [_c, _i, _u, a], _ in assoc(a, :badge))
# |> preload([_c, i, u, a, b], [:deleted_by, image: i, user: {u, awards: {a, badge: b}}])
def load_comments(conn, image) do
pref = load_direction(conn.assigns.current_user)

View file

@ -147,12 +147,8 @@ defmodule PhilomenaWeb.ImageController do
|> where(id: ^id)
|> join(:inner_lateral, [i], _ in fragment("SELECT COUNT(*) FROM tag_changes t WHERE t.image_id = ?", i.id))
|> join(:inner_lateral, [i, _], _ in fragment("SELECT COUNT(*) FROM source_changes s WHERE s.image_id = ?", i.id))
|> join(:left, [i, _tc, _sc], _ in assoc(i, :user))
|> join(:left, [_i, _tc, _sc, u], _ in assoc(u, :awards))
|> join(:left, [_i, _tc, _sc, _u, a], _ in assoc(a, :badge))
|> join(:left, [i, _tc, _sc, _u, _a, _b], _ in assoc(i, :tags))
|> preload([_i, _tc, _sc, u, a, b, t], [:deleter, tags: t, user: {u, awards: {a, badge: b}}])
|> select([i, tc, sc, _u], {i, tc.count, sc.count})
|> preload([:tags, :deleter, user: [awards: :badge]])
|> select([i, t, s], {i, t.count, s.count})
|> Repo.one()
|> case do
nil ->

View file

@ -20,7 +20,7 @@ defmodule PhilomenaWeb.ImageLoader do
sort_queries = Keyword.get(options, :queries, [])
sort_sorts = Keyword.get(options, :sorts, [%{created_at: :desc}])
pagination = Keyword.get(options, :pagination, conn.assigns.image_pagination)
queryable = Keyword.get(options, :queryable, default_queryable())
queryable = Keyword.get(options, :queryable, Image |> preload(:tags))
user = conn.assigns.current_user
filter = conn.assigns.compiled_filter
@ -126,10 +126,4 @@ defmodule PhilomenaWeb.ImageLoader do
[{tag, description, dnp_entries}]
end
defp render_bodies(tags, _conn), do: tags
defp default_queryable do
Image
|> join(:left, [i], _ in assoc(i, :tags))
|> preload([_i, t], tags: t)
end
end

View file

@ -24,4 +24,4 @@ defmodule PhilomenaWeb.AdvertPlug do
do: true
defp show_ads?(_user),
do: true
end
end