More ActiveRecord Association .length -> .size Optimizations
This commit is contained in:
parent
342298ed0e
commit
34c4306867
|
@ -26,7 +26,7 @@ module CacheSweepingHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def expire_cached_revisions(page)
|
def expire_cached_revisions(page)
|
||||||
page.revisions.length.times do |i|
|
page.revisions.count.times do |i|
|
||||||
revno = i+1
|
revno = i+1
|
||||||
expire_action :controller => 'wiki', :web => page.web.address,
|
expire_action :controller => 'wiki', :web => page.web.address,
|
||||||
:action => 'revision', :id => page.name, :rev => revno
|
:action => 'revision', :id => page.name, :rev => revno
|
||||||
|
|
|
@ -19,7 +19,7 @@ class WikiController < ApplicationController
|
||||||
redirect_home
|
redirect_home
|
||||||
elsif not @wiki.setup?
|
elsif not @wiki.setup?
|
||||||
redirect_to :controller => 'admin', :action => 'create_system'
|
redirect_to :controller => 'admin', :action => 'create_system'
|
||||||
elsif @wiki.webs.length == 1
|
elsif @wiki.webs.size == 1
|
||||||
redirect_home @wiki.webs.values.first.address
|
redirect_home @wiki.webs.values.first.address
|
||||||
else
|
else
|
||||||
redirect_to :action => 'web_list'
|
redirect_to :action => 'web_list'
|
||||||
|
@ -345,7 +345,7 @@ class WikiController < ApplicationController
|
||||||
if @page
|
if @page
|
||||||
@revisions_by_day = Hash.new { |h, day| h[day] = [] }
|
@revisions_by_day = Hash.new { |h, day| h[day] = [] }
|
||||||
@revision_numbers = Hash.new { |h, id| h[id] = [] }
|
@revision_numbers = Hash.new { |h, id| h[id] = [] }
|
||||||
revision_number = @page.revisions.length
|
revision_number = @page.revisions.size
|
||||||
@page.revisions.reverse.each do |rev|
|
@page.revisions.reverse.each do |rev|
|
||||||
day = Date.new(rev.revised_at.year, rev.revised_at.month, rev.revised_at.day)
|
day = Date.new(rev.revised_at.year, rev.revised_at.month, rev.revised_at.day)
|
||||||
@revisions_by_day[day] << rev
|
@revisions_by_day[day] << rev
|
||||||
|
@ -462,7 +462,7 @@ class WikiController < ApplicationController
|
||||||
if params['rev']
|
if params['rev']
|
||||||
@revision_number = params['rev'].to_i
|
@revision_number = params['rev'].to_i
|
||||||
else
|
else
|
||||||
@revision_number = @page.revisions.length
|
@revision_number = @page.revisions.size
|
||||||
end
|
end
|
||||||
@revision = @page.revisions[@revision_number - 1]
|
@revision = @page.revisions[@revision_number - 1]
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,7 +54,7 @@ module ApplicationHelper
|
||||||
|
|
||||||
# Create a hyperlink to a particular revision of a Wiki page
|
# Create a hyperlink to a particular revision of a Wiki page
|
||||||
def link_to_revision(page, revision_number, text = nil, mode = nil, html_options = {})
|
def link_to_revision(page, revision_number, text = nil, mode = nil, html_options = {})
|
||||||
revision_number == page.revisions.length ?
|
revision_number == page.revisions.size ?
|
||||||
link_to(
|
link_to(
|
||||||
text || page.plain_name,
|
text || page.plain_name,
|
||||||
{:web => @web.address, :action => 'show', :id => page.name,
|
{:web => @web.address, :action => 'show', :id => page.name,
|
||||||
|
|
|
@ -6,7 +6,7 @@ module WikiHelper
|
||||||
menu << back_for_revision if @revision_number > 1
|
menu << back_for_revision if @revision_number > 1
|
||||||
menu << current_revision
|
menu << current_revision
|
||||||
menu << see_or_hide_changes_for_revision if @revision_number > 1
|
menu << see_or_hide_changes_for_revision if @revision_number > 1
|
||||||
menu << history if @page.revisions.length > 1
|
menu << history if @page.revisions.size > 1
|
||||||
menu << rollback
|
menu << rollback
|
||||||
menu
|
menu
|
||||||
end
|
end
|
||||||
|
@ -15,11 +15,11 @@ module WikiHelper
|
||||||
menu = []
|
menu = []
|
||||||
menu << edit_page
|
menu << edit_page
|
||||||
menu << edit_web if @page.name == "HomePage"
|
menu << edit_web if @page.name == "HomePage"
|
||||||
if @page.revisions.length > 1
|
if @page.revisions.size > 1
|
||||||
menu << back_for_page
|
menu << back_for_page
|
||||||
menu << see_or_hide_changes_for_page
|
menu << see_or_hide_changes_for_page
|
||||||
end
|
end
|
||||||
menu << history if @page.revisions.length > 1
|
menu << history if @page.revisions.size > 1
|
||||||
menu
|
menu
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,11 +40,11 @@ module WikiHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def forward
|
def forward
|
||||||
if @revision_number < @page.revisions.length - 1
|
if @revision_number < @page.revisions.size - 1
|
||||||
link_to('Forward in time',
|
link_to('Forward in time',
|
||||||
{:web => @web.address, :action => 'revision', :id => @page.name, :rev => @revision_number + 1},
|
{:web => @web.address, :action => 'revision', :id => @page.name, :rev => @revision_number + 1},
|
||||||
{:class => 'navlink', :accesskey => 'F', :id => 'to_next_revision', :rel => 'nofollow'}) +
|
{:class => 'navlink', :accesskey => 'F', :id => 'to_next_revision', :rel => 'nofollow'}) +
|
||||||
" <span class='revisions'>(#{@revision.page.revisions.length - @revision_number} more)</span> "
|
" <span class='revisions'>(#{@revision.page.revisions.size - @revision_number} more)</span> "
|
||||||
else
|
else
|
||||||
link_to('Forward in time', {:web => @web.address, :action => 'show', :id => @page.name},
|
link_to('Forward in time', {:web => @web.address, :action => 'show', :id => @page.name},
|
||||||
{:class => 'navlink', :accesskey => 'F', :id => 'to_next_revision', :rel => 'nofollow'}) +
|
{:class => 'navlink', :accesskey => 'F', :id => 'to_next_revision', :rel => 'nofollow'}) +
|
||||||
|
@ -62,9 +62,9 @@ module WikiHelper
|
||||||
def back_for_page
|
def back_for_page
|
||||||
link_to('Back in time',
|
link_to('Back in time',
|
||||||
{:web => @web.address, :action => 'revision', :id => @page.name,
|
{:web => @web.address, :action => 'revision', :id => @page.name,
|
||||||
:rev => @page.revisions.length - 1},
|
:rev => @page.revisions.size - 1},
|
||||||
{:class => 'navlink', :accesskey => 'B', :id => 'to_previous_revision', :rel => 'nofollow'}) +
|
{:class => 'navlink', :accesskey => 'B', :id => 'to_previous_revision', :rel => 'nofollow'}) +
|
||||||
" <span class='revisions'>(#{@page.revisions.length - 1} #{@page.revisions.length - 1 == 1 ? 'revision' : 'revisions'})</span>"
|
" <span class='revisions'>(#{@page.revisions.size - 1} #{@page.revisions.size - 1 == 1 ? 'revision' : 'revisions'})</span>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_revision
|
def current_revision
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<%- for rev in @revisions_by_day[day] -%>
|
<%- for rev in @revisions_by_day[day] -%>
|
||||||
<li>
|
<li>
|
||||||
<%= link_to_revision(rev.page, @revision_numbers[rev.id],
|
<%= link_to_revision(rev.page, @revision_numbers[rev.id],
|
||||||
text= (rev.page.revisions.length == @revision_numbers[rev.id] ?
|
text= (rev.page.revisions.size == @revision_numbers[rev.id] ?
|
||||||
"Current" :
|
"Current" :
|
||||||
"Revision #{@revision_numbers[rev.id]}" )
|
"Revision #{@revision_numbers[rev.id]}" )
|
||||||
) %>
|
) %>
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
|
|
||||||
<div class="byline" style="margin-bottom: 0px">
|
<div class="byline" style="margin-bottom: 0px">
|
||||||
<%= web.pages.length %> page<% if web.pages.length != 1 %>s<% end %> by <%= web.authors.length %> author<% if web.authors.length != 1 %>s<% end %>
|
<%= web.pages.size %> page<% if web.pages.size != 1 %>s<% end %> by <%= web.authors.size %> author<% if web.authors.size != 1 %>s<% end %>
|
||||||
- Last Update: <%= web.last_page.nil? ? format_date(web.created_at) : format_date(web.last_page.revised_at) %><br/>
|
- Last Update: <%= web.last_page.nil? ? format_date(web.created_at) : format_date(web.last_page.revised_at) %><br/>
|
||||||
<%- if ! web.last_page.nil? -%>
|
<%- if ! web.last_page.nil? -%>
|
||||||
Last Document: <%= link_to_page(web.last_page.name,web) %>
|
Last Document: <%= link_to_page(web.last_page.name,web) %>
|
||||||
|
|
Loading…
Reference in a new issue