mirror of
https://github.com/redmine/redmine.git
synced 2025-12-16 05:20:28 +01:00
Evaluate acts_as_activity_provider's scope lazily (#33664).
Patch by Pavel Rosický. git-svn-id: http://svn.redmine.org/redmine/trunk@20148 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -38,16 +38,20 @@ class Attachment < ActiveRecord::Base
|
||||
acts_as_activity_provider :type => 'files',
|
||||
:permission => :view_files,
|
||||
:author_key => :author_id,
|
||||
:scope => select("#{Attachment.table_name}.*").
|
||||
:scope => proc {
|
||||
select("#{Attachment.table_name}.*").
|
||||
joins("LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
|
||||
"LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id OR ( #{Attachment.table_name}.container_type='Project' AND #{Attachment.table_name}.container_id = #{Project.table_name}.id )")
|
||||
}
|
||||
|
||||
acts_as_activity_provider :type => 'documents',
|
||||
:permission => :view_documents,
|
||||
:author_key => :author_id,
|
||||
:scope => select("#{Attachment.table_name}.*").
|
||||
:scope => proc {
|
||||
select("#{Attachment.table_name}.*").
|
||||
joins("LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
|
||||
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id")
|
||||
}
|
||||
|
||||
cattr_accessor :storage_path
|
||||
@@storage_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files")
|
||||
|
||||
@@ -43,7 +43,7 @@ class Changeset < ActiveRecord::Base
|
||||
|
||||
acts_as_activity_provider :timestamp => "#{table_name}.committed_on",
|
||||
:author_key => :user_id,
|
||||
:scope => preload(:user, {:repository => :project})
|
||||
:scope => proc { preload(:user, {:repository => :project}) }
|
||||
|
||||
validates_presence_of :repository_id, :revision, :committed_on, :commit_date
|
||||
validates_uniqueness_of :revision, :scope => :repository_id
|
||||
|
||||
@@ -29,7 +29,7 @@ class Document < ActiveRecord::Base
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
|
||||
:author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) },
|
||||
:url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
|
||||
acts_as_activity_provider :scope => preload(:project)
|
||||
acts_as_activity_provider :scope => proc { preload(:project) }
|
||||
|
||||
validates_presence_of :project, :title, :category
|
||||
validates_length_of :title, :maximum => 255
|
||||
|
||||
@@ -51,7 +51,7 @@ class Issue < ActiveRecord::Base
|
||||
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}},
|
||||
:type => Proc.new {|o| 'issue' + (o.closed? ? '-closed' : '')}
|
||||
|
||||
acts_as_activity_provider :scope => preload(:project, :author, :tracker, :status),
|
||||
acts_as_activity_provider :scope => proc { preload(:project, :author, :tracker, :status) },
|
||||
:author_key => :author_id
|
||||
|
||||
DONE_RATIO_OPTIONS = %w(issue_field issue_status)
|
||||
|
||||
@@ -38,10 +38,12 @@ class Journal < ActiveRecord::Base
|
||||
|
||||
acts_as_activity_provider :type => 'issues',
|
||||
:author_key => :user_id,
|
||||
:scope => preload({:issue => :project}, :user).
|
||||
:scope => proc {
|
||||
preload({:issue => :project}, :user).
|
||||
joins("LEFT OUTER JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id").
|
||||
where("#{Journal.table_name}.journalized_type = 'Issue' AND" +
|
||||
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')").distinct
|
||||
}
|
||||
|
||||
before_create :split_private_notes
|
||||
after_create_commit :send_notification
|
||||
|
||||
@@ -45,7 +45,7 @@ class Message < ActiveRecord::Base
|
||||
end)
|
||||
}
|
||||
|
||||
acts_as_activity_provider :scope => preload({:board => :project}, :author),
|
||||
acts_as_activity_provider :scope => proc { preload({:board => :project}, :author) },
|
||||
:author_key => :author_id
|
||||
acts_as_watchable
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class News < ActiveRecord::Base
|
||||
acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"],
|
||||
:preload => :project
|
||||
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
|
||||
acts_as_activity_provider :scope => preload(:project, :author),
|
||||
acts_as_activity_provider :scope => proc { preload(:project, :author) },
|
||||
:author_key => :author_id
|
||||
acts_as_watchable
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class TimeEntry < ActiveRecord::Base
|
||||
|
||||
acts_as_activity_provider :timestamp => "#{table_name}.created_on",
|
||||
:author_key => :user_id,
|
||||
:scope => joins(:project).preload(:project)
|
||||
:scope => proc { joins(:project).preload(:project) }
|
||||
|
||||
validates_presence_of :author_id, :user_id, :activity_id, :project_id, :hours, :spent_on
|
||||
validates_presence_of :issue_id, :if => lambda { Setting.timelog_required_fields.include?('issue_id') }
|
||||
|
||||
@@ -34,13 +34,15 @@ class WikiContentVersion < ActiveRecord::Base
|
||||
:timestamp => "#{table_name}.updated_on",
|
||||
:author_key => "#{table_name}.author_id",
|
||||
:permission => :view_wiki_edits,
|
||||
:scope => select("#{table_name}.updated_on, #{table_name}.comments, " +
|
||||
:scope => proc {
|
||||
select("#{table_name}.updated_on, #{table_name}.comments, " +
|
||||
"#{table_name}.version, #{WikiPage.table_name}.title, " +
|
||||
"#{table_name}.page_id, #{table_name}.author_id, " +
|
||||
"#{table_name}.id").
|
||||
joins("LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{table_name}.page_id " +
|
||||
"LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
|
||||
"LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id")
|
||||
}
|
||||
|
||||
after_destroy :page_update_after_destroy
|
||||
|
||||
|
||||
@@ -7,6 +7,6 @@ class Meeting < ActiveRecord::Base
|
||||
:url => Proc.new {|o| {:controller => 'meetings', :action => 'show', :id => o.id}}
|
||||
|
||||
acts_as_activity_provider :timestamp => 'scheduled_on',
|
||||
:scope => includes(:project),
|
||||
:scope => proc { includes(:project) },
|
||||
:permission => nil
|
||||
end
|
||||
|
||||
@@ -55,7 +55,14 @@ module Redmine
|
||||
provider_options = activity_provider_options[event_type]
|
||||
raise "#{self.name} can not provide #{event_type} events." if provider_options.nil?
|
||||
|
||||
scope = (provider_options[:scope] || self)
|
||||
scope = provider_options[:scope]
|
||||
if !scope
|
||||
scope = self
|
||||
elsif scope.respond_to?(:call)
|
||||
scope = scope.call
|
||||
else
|
||||
ActiveSupport::Deprecation.warn "acts_as_activity_provider with implicit :scope option is deprecated. Please pass a scope on the #{self.name} as a proc."
|
||||
end
|
||||
|
||||
if from && to
|
||||
scope = scope.where("#{provider_options[:timestamp]} BETWEEN ? AND ?", from, to)
|
||||
|
||||
Reference in New Issue
Block a user