Moved wiki page updated_on eager load to a scope and fixed timestamp titles on wiki page index (#7818).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5098 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2011-03-12 18:09:46 +00:00
parent f7127e9466
commit b8b35ab05f
5 changed files with 45 additions and 22 deletions
+18
View File
@@ -41,6 +41,12 @@ class WikiPage < ActiveRecord::Base
validates_uniqueness_of :title, :scope => :wiki_id, :case_sensitive => false
validates_associated :content
# eager load information about last updates, without loading text
named_scope :with_updated_on, {
:select => "#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on",
:joins => "LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id"
}
# Wiki pages that are protected by default
DEFAULT_PROTECTED_PAGES = %w(sidebar)
@@ -121,6 +127,18 @@ class WikiPage < ActiveRecord::Base
content.text if content
end
def updated_on
unless @updated_on
if time = read_attribute(:updated_on)
# content updated_on was eager loaded with the page
@updated_on = Time.parse(time) rescue nil
else
@updated_on = content && content.updated_on
end
end
@updated_on
end
# Returns true if usr is allowed to edit the page, otherwise false
def editable_by?(usr)
!protected? || usr.allowed_to?(:protect_wiki_pages, wiki.project)