Load less data in indexing

This commit is contained in:
Liam 2025-01-11 16:25:19 -05:00
parent 77ed150dd9
commit 0d6bc6cee1
3 changed files with 43 additions and 10 deletions

View file

@ -9,11 +9,13 @@ defmodule Philomena.Comments do
alias PhilomenaQuery.Search
alias Philomena.UserStatistics
alias Philomena.Users.User
alias Philomena.Comments.Comment
alias Philomena.Comments.SearchIndex, as: CommentIndex
alias Philomena.IndexWorker
alias Philomena.Images.Image
alias Philomena.Images
alias Philomena.Tags.Tag
alias Philomena.Notifications
alias Philomena.Versions
alias Philomena.Reports
@ -234,7 +236,18 @@ defmodule Philomena.Comments do
end
def indexing_preloads do
[:user, image: :tags]
user_query = select(User, [u], map(u, [:id, :name]))
tag_query = select(Tag, [t], map(t, [:id]))
image_query =
Image
|> select([i], struct(i, [:approved, :hidden_from_users, :id]))
|> preload(tags: ^tag_query)
[
user: user_query,
image: image_query
]
end
def perform_reindex(column, condition) do

View file

@ -847,16 +847,25 @@ defmodule Philomena.Images do
end
def indexing_preloads do
user_query = select(User, [u], map(u, [:id, :name]))
sources_query = select(Source, [s], map(s, [:image_id, :source]))
alias_tags_query = select(Tag, [t], map(t, [:aliased_tag_id, :name]))
base_tags_query =
Tag
|> select([t], [:category, :id, :name])
|> preload(aliases: ^alias_tags_query)
[
:user,
:favers,
:downvoters,
:upvoters,
:hiders,
:deleter,
:gallery_interactions,
:sources,
tags: [:aliases, :aliased_tag]
sources: sources_query,
user: user_query,
favers: user_query,
downvoters: user_query,
upvoters: user_query,
hiders: user_query,
deleter: user_query,
tags: base_tags_query
]
end

View file

@ -11,6 +11,7 @@ defmodule Philomena.Posts do
alias Philomena.Topics.Topic
alias Philomena.Topics
alias Philomena.UserStatistics
alias Philomena.Users.User
alias Philomena.Posts.Post
alias Philomena.Posts.SearchIndex, as: PostIndex
alias Philomena.IndexWorker
@ -279,7 +280,17 @@ defmodule Philomena.Posts do
end
def indexing_preloads do
[:user, topic: :forum]
user_query = select(User, [u], map(u, [:id, :name]))
topic_query =
Topic
|> select([t], struct(t, [:forum_id, :title]))
|> preload([:forum])
[
user: user_query,
topic: topic_query
]
end
def perform_reindex(column, condition) do