summaryrefslogtreecommitdiffstats
path: root/app/models/wiki_page.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-09-28 18:39:07 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-09-28 18:39:07 +0000
commit2d78003c87099fb6a832025027701e9456727727 (patch)
tree555f64d08425a12b2ebda16f5dea3ac41cee979f /app/models/wiki_page.rb
parent63bc3d4f89a688681f83a49b1eb8f4d320f8ac03 (diff)
downloadredmine-2d78003c87099fb6a832025027701e9456727727.tar.gz
redmine-2d78003c87099fb6a832025027701e9456727727.zip
Replaces a piggy back query with an association for loading wiki pages updates.
git-svn-id: http://svn.redmine.org/redmine/trunk@14625 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/wiki_page.rb')
-rw-r--r--app/models/wiki_page.rb30
1 files changed, 14 insertions, 16 deletions
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index ff8a12a99..988819a77 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -23,6 +23,8 @@ class WikiPage < ActiveRecord::Base
belongs_to :wiki
has_one :content, :class_name => 'WikiContent', :foreign_key => 'page_id', :dependent => :destroy
+ has_one :content_without_text, lambda {without_text.readonly}, :class_name => 'WikiContent', :foreign_key => 'page_id'
+
acts_as_attachable :delete_permission => :delete_wiki_pages_attachments
acts_as_tree :dependent => :nullify, :order => 'title'
@@ -52,10 +54,7 @@ class WikiPage < ActiveRecord::Base
after_save :handle_children_move
# eager load information about last updates, without loading text
- scope :with_updated_on, lambda {
- select("#{WikiPage.table_name}.*, #{WikiContent.table_name}.updated_on, #{WikiContent.table_name}.version").
- joins("LEFT JOIN #{WikiContent.table_name} ON #{WikiContent.table_name}.page_id = #{WikiPage.table_name}.id")
- }
+ scope :with_updated_on, lambda { preload(:content_without_text) }
# Wiki pages that are protected by default
DEFAULT_PROTECTED_PAGES = %w(sidebar)
@@ -183,18 +182,11 @@ class WikiPage < ActiveRecord::Base
end
def updated_on
- unless @updated_on
- if time = read_attribute(:updated_on)
- # content updated_on was eager loaded with the page
- begin
- @updated_on = (self.class.default_timezone == :utc ? Time.parse(time.to_s).utc : Time.parse(time.to_s).localtime)
- rescue
- end
- else
- @updated_on = content && content.updated_on
- end
- end
- @updated_on
+ content_attribute(:updated_on)
+ end
+
+ def version
+ content_attribute(:version)
end
# Returns true if usr is allowed to edit the page, otherwise false
@@ -244,6 +236,12 @@ class WikiPage < ActiveRecord::Base
errors.add(:parent_title, :not_same_project)
end
end
+
+ private
+
+ def content_attribute(name)
+ (association(:content).loaded? ? content : content_without_text).try(name)
+ end
end
class WikiDiff < Redmine::Helpers::Diff