diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-03-12 18:09:46 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-03-12 18:09:46 +0000 |
commit | b8b35ab05f70e6edd524397d2fb0dca3630fa840 (patch) | |
tree | 47b6925e19f643969a019a5ca094f4a197777bad /app/models/wiki_page.rb | |
parent | f7127e9466861af2a8ea11624e619e6567890a36 (diff) | |
download | redmine-b8b35ab05f70e6edd524397d2fb0dca3630fa840.tar.gz redmine-b8b35ab05f70e6edd524397d2fb0dca3630fa840.zip |
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
Diffstat (limited to 'app/models/wiki_page.rb')
-rw-r--r-- | app/models/wiki_page.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 8cd836a31..923f381b7 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -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) |