Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed improvements for /admin/pages/ #921

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/helpers/alchemy/admin/pages_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary, since Alchemy is Ruby >= 2 and utf-8 is default encoding

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was added automatically by Emacs. Feel free to remove it, although in my opinion it's not a bad idea to keep it there. Some editors don't detect file encoding automatically.

module Alchemy
module Admin
module PagesHelper
Expand Down Expand Up @@ -65,6 +66,19 @@ def page_layout_label(page)
_t(:page_type)
end
end

# Returns a flat tree structure of all the pages, with level a indication,
# starting from root. Format: [[page, level], [page, level], ...]
#
def pages_tree_from(root)
tree = []

Alchemy::Page.each_with_level(root.self_and_descendants) do |page, level|
tree << [page, level]
end

tree
end
end
end
end
6 changes: 6 additions & 0 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ class << self

alias_method :rootpage, :root

# Make sure Page.root does not hit the database all the time.
#
def root
RequestStore.store[:alchemy_page_root] ||= super
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great idea!

end

# Used to store the current page previewed in the edit page template.
#
def current_preview=(page)
Expand Down
112 changes: 0 additions & 112 deletions app/views/alchemy/admin/pages/_page.html.erb

This file was deleted.

117 changes: 117 additions & 0 deletions app/views/alchemy/admin/pages/_pages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<%- tree = pages_tree_from(root) -%>
<%- tree.each_with_index do |(page, level), i| -%>
<%- page_has_children = tree[i + 1] && tree[i + 1][1] > level -%>
<li id="page_<%= page.id %>" class="page_level_<%= "#{level} #{page.page_layout}" %>" data-slug="<%= page.slug %>" data-restricted="<%= page.restricted? %>" data-visible="<%= page.visible? %>" data-external="<%= page.redirects_to_external? %>">
<div class="sitemap_page<%= page.locked ? ' locked' : '' %>" name="<%= page.name %>">
<div class="sitemap_left_images">
<% sitemap_folder_link(page) unless level == 1 || !page_has_children || @sorting %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<%= sitemap_folder_link(page), ..

without loud erb the folder link isn't visible, but maybe it's intended by you, because the folding doesn't work anymore, because of missing page partial

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Folding is broken at the moment. Also in the client side approach. Since we're going for the client side approach, I didn't bother fixing that just yet in this pull request.

<%- if page.layout_description.blank? -%>
<span class="inline warning icon" title="<%= _t(:page_layout_description_missing) %>"></span>
<%- else -%>
<div class="page icon <%= @sorting && level > 1 ? 'handle' : nil %>"></div>
<%- end -%>
</div>
<div class="sitemap_right_tools">
<%- unless @sorting -%>
<%- if can?(:info, page) -%>
<%= link_to_dialog(
render_icon('info'),
alchemy.info_admin_page_path(page),
{
title: _t(:page_infos),
size: '520x290'
},
{
title: _t(:page_infos),
class: 'sitemap_tool'
}
) %>
<%- end -%>
<%- if can?(:configure, page) -%>
<%= link_to_dialog(
render_icon('configure_page'),
alchemy.configure_admin_page_path(page),
{
title: _t(:edit_page_properties),
size: page.redirects_to_external? ? '450x330' : '450x720'
},
title: _t(:edit_page_properties),
class: 'sitemap_tool'
) -%>
<%- end -%>
<span class="sitemap_sitetools">
<%- if can?(:copy, page) -%>
<%= link_to(
render_icon("copy_page"),
alchemy.insert_admin_clipboard_path(
remarkable_type: page.class.name.demodulize.underscore.pluralize,
remarkable_id: page.id
),
remote: true,
method: 'post',
title: _t(:copy_page),
class: 'sitemap_tool'
) %>
<%- end -%>
<%- if can?(:destroy, page) -%>
<%= link_to_confirm_dialog(
render_icon('delete_page'),
_t(:confirm_to_delete_page),
url_for(
controller: 'pages',
action: 'destroy',
id: page.id
),
{
title: _t(:delete_page),
class: 'sitemap_tool'
}
) -%>
<%- end -%>
<%- if can?(:create, Alchemy::Page) -%>
<%= link_to_dialog(
render_icon('add_page'),
alchemy.new_admin_page_path(parent_id: page.id),
{
title: _t(:create_page),
size: '340x165',
overflow: true
},
title: _t(:create_page),
class: 'sitemap_tool'
) -%>
<%- end -%>
</span>
<%- end -%>
</div>
<div class="page_infos" id="page_<%= page.id %>_infos">
<span class="page_status <%= page.public ? 'public' : 'not_public' %>" title="<%= page.status_title(:public) %>"></span>
<span class="page_status <%= page.visible ? 'visible' : 'not_visible' %>" title="<%= page.status_title(:visible) %>"></span>
<span class="page_status <%= page.restricted ? 'restricted' : 'not_restricted' %>" title="<%= page.status_title(:restricted) %>"></span>
</div>
<div class="sitemap_sitename">
<%- if page.redirects_to_external? -%>
<span class="sitemap_pagename_link inactive"><%= page.name %></span>
<span class="redirect_url" title="<%= h page.urlname %>">
&raquo; <%= _t('Redirects to') %>:
<%= h page.external_urlname %>
</span>
<%- else -%>
<%= link_to_unless(
@sorting,
page.name,
alchemy.edit_admin_page_path(page),
title: _t(:edit_page),
class: "sitemap_pagename_link"
) { content_tag('span', page.name, class: "sitemap_pagename_link") } -%>
<%- end -%>
</div>
</div>
<%- if @sorting || (page_has_children && !page.folded?(current_alchemy_user)) -%>
<ul id="page_<%= page.id %>_children" class="level_<%= level %>_children">
<%- elsif !tree[i + 1] || tree[i + 1][1] < level -%>
<%- (level - (tree[i + 1] ? tree[i + 1][1] : 1)).times do -%></li></ul><%- end -%>
<%- else -%>
</li>
<%- end -%>
<%- end -%>
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/pages/_sitemap.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ul id="sitemap" class="list<%= @sorting ? ' sorting' : nil %>">
<%= render :partial => 'page', :object => @page_root %>
<%= render partial: 'pages', locals: {root: @page_root} %>
</ul>
<script type="text/javascript">
$(function() {
Expand Down