-
-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip folded deeper levels when rendering page tree
Previously the page tree was rendered in full even if pages are folded. Consider the following tree: even if level 1 was folded, level 2 and 3 would get rendered and sent to the client. - root |+ level 1 |- level 2 |- level 3 This change does two things: 1. load all user-folded pages for the current user in advance, reducing the number of queries to 1 2. skips all pages that are under a folded page The result is: - root |+ level 1 Together with 5a4c0d3 this speeds up the page tree rendering from 20 seconds to ~100ms when only 10 folded pages are shown (Alchemy::Page.count == 4000).
- Loading branch information
Showing
3 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require "spec_helper" | ||
|
||
module Alchemy | ||
class NonArDummyUser; end | ||
|
||
describe FoldedPage do | ||
describe "folded_for_user" do | ||
subject(:folded_for_user) { described_class.folded_for_user(user) } | ||
let(:user) { create(:alchemy_dummy_user) } | ||
|
||
context "with a non-AR user_class" do | ||
around :each do |example| | ||
before = Alchemy.user_class_name | ||
Alchemy.user_class_name = "NonArDummyUser" | ||
example.run | ||
Alchemy.user_class_name = before | ||
end | ||
let(:user) { NonArDummyUser.new } | ||
|
||
it "does not raise an error" do | ||
expect { | ||
folded_for_user | ||
}.not_to raise_error | ||
end | ||
end | ||
|
||
context "with folded pages" do | ||
let(:page) { create(:alchemy_page) } | ||
let(:other_user) { create(:alchemy_dummy_user) } | ||
let!(:user_folded) { FoldedPage.create(user: user, page: page, folded: true) } | ||
let!(:other_user_folded) { FoldedPage.create(user: other_user, page: page, folded: true) } | ||
|
||
it { is_expected.to include(user_folded) } | ||
it { is_expected.to_not include(other_user_folded) } | ||
end | ||
end | ||
end | ||
end |