Skip to content

Commit b3ae52b

Browse files
committed
Make page tree loader class configurable
If someone wants to adjust how we preload whole page trees they can confgure a different class. Signed-off-by: Thomas von Deyen <[email protected]>
1 parent e76c2ce commit b3ae52b

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

app/controllers/alchemy/admin/pages_controller.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def index
5757
items = items.page(params[:page] || 1).per(items_per_page)
5858
@pages = items
5959
elsif @current_language.root_page
60-
@root_page = Alchemy::PageTreePreloader.new(
60+
@root_page = Alchemy.config.page_tree_loader_class.new(
6161
page: @current_language.root_page,
6262
user: current_alchemy_user
6363
).call
@@ -173,7 +173,10 @@ def fold
173173
respond_to do |format|
174174
format.turbo_stream do
175175
if was_folded
176-
@page = PageTreePreloader.new(page: @page, user: current_alchemy_user).call
176+
@page = Alchemy.config.page_tree_loader_class.new(
177+
page: @page,
178+
user: current_alchemy_user
179+
).call
177180
else
178181
head :ok
179182
end

app/controllers/alchemy/api/pages_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ def nested
2929
@page = Page.find_by(id: params[:page_id]) || Language.current_root_page
3030

3131
# Preload the full tree from this page
32-
preloaded_page = PageTreePreloader.new(page: @page, user: current_alchemy_user).call
32+
preloaded_page = Alchemy.config.page_tree_loader_class.new(
33+
page: @page,
34+
user: current_alchemy_user
35+
).call
3336

3437
render json: PageTreeSerializer.new(
3538
preloaded_page,

lib/alchemy/configurations/main.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,14 @@ class Main < Alchemy::Configuration
378378
# Default is 1 hour.
379379
#
380380
option :update_check_cache_duration, :integer, default: 1
381+
382+
# === Page tree loader class
383+
#
384+
# The class used to preload page trees with all associations and children.
385+
# Must respond to .new(page:, user:).call
386+
#
387+
# @default Alchemy::PageTreePreloader
388+
option :page_tree_loader_class, :class, default: "Alchemy::PageTreePreloader"
381389
end
382390
end
383391
end

0 commit comments

Comments
 (0)