Skip to content

Commit e48ff48

Browse files
committed
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
1 parent d9c6249 commit e48ff48

File tree

11 files changed

+27
-12
lines changed

11 files changed

+27
-12
lines changed

app/models/attachment.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,20 @@ class Attachment < ActiveRecord::Base
3838
acts_as_activity_provider :type => 'files',
3939
:permission => :view_files,
4040
:author_key => :author_id,
41-
:scope => select("#{Attachment.table_name}.*").
41+
:scope => proc {
42+
select("#{Attachment.table_name}.*").
4243
joins("LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
4344
"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 )")
45+
}
4446

4547
acts_as_activity_provider :type => 'documents',
4648
:permission => :view_documents,
4749
:author_key => :author_id,
48-
:scope => select("#{Attachment.table_name}.*").
50+
:scope => proc {
51+
select("#{Attachment.table_name}.*").
4952
joins("LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
5053
"LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id")
54+
}
5155

5256
cattr_accessor :storage_path
5357
@@storage_path = Redmine::Configuration['attachments_storage_path'] || File.join(Rails.root, "files")

app/models/changeset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Changeset < ActiveRecord::Base
4343

4444
acts_as_activity_provider :timestamp => "#{table_name}.committed_on",
4545
:author_key => :user_id,
46-
:scope => preload(:user, {:repository => :project})
46+
:scope => proc { preload(:user, {:repository => :project}) }
4747

4848
validates_presence_of :repository_id, :revision, :committed_on, :commit_date
4949
validates_uniqueness_of :revision, :scope => :repository_id

app/models/document.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Document < ActiveRecord::Base
2929
acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
3030
:author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) },
3131
:url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
32-
acts_as_activity_provider :scope => preload(:project)
32+
acts_as_activity_provider :scope => proc { preload(:project) }
3333

3434
validates_presence_of :project, :title, :category
3535
validates_length_of :title, :maximum => 255

app/models/issue.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Issue < ActiveRecord::Base
5151
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}},
5252
:type => Proc.new {|o| 'issue' + (o.closed? ? '-closed' : '')}
5353

54-
acts_as_activity_provider :scope => preload(:project, :author, :tracker, :status),
54+
acts_as_activity_provider :scope => proc { preload(:project, :author, :tracker, :status) },
5555
:author_key => :author_id
5656

5757
DONE_RATIO_OPTIONS = %w(issue_field issue_status)

app/models/journal.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ class Journal < ActiveRecord::Base
3838

3939
acts_as_activity_provider :type => 'issues',
4040
:author_key => :user_id,
41-
:scope => preload({:issue => :project}, :user).
41+
:scope => proc {
42+
preload({:issue => :project}, :user).
4243
joins("LEFT OUTER JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id").
4344
where("#{Journal.table_name}.journalized_type = 'Issue' AND" +
4445
" (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')").distinct
46+
}
4547

4648
before_create :split_private_notes
4749
after_create_commit :send_notification

app/models/message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Message < ActiveRecord::Base
4545
end)
4646
}
4747

48-
acts_as_activity_provider :scope => preload({:board => :project}, :author),
48+
acts_as_activity_provider :scope => proc { preload({:board => :project}, :author) },
4949
:author_key => :author_id
5050
acts_as_watchable
5151

app/models/news.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class News < ActiveRecord::Base
3232
acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"],
3333
:preload => :project
3434
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
35-
acts_as_activity_provider :scope => preload(:project, :author),
35+
acts_as_activity_provider :scope => proc { preload(:project, :author) },
3636
:author_key => :author_id
3737
acts_as_watchable
3838

app/models/time_entry.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class TimeEntry < ActiveRecord::Base
4141

4242
acts_as_activity_provider :timestamp => "#{table_name}.created_on",
4343
:author_key => :user_id,
44-
:scope => joins(:project).preload(:project)
44+
:scope => proc { joins(:project).preload(:project) }
4545

4646
validates_presence_of :author_id, :user_id, :activity_id, :project_id, :hours, :spent_on
4747
validates_presence_of :issue_id, :if => lambda { Setting.timelog_required_fields.include?('issue_id') }

app/models/wiki_content_version.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ class WikiContentVersion < ActiveRecord::Base
3434
:timestamp => "#{table_name}.updated_on",
3535
:author_key => "#{table_name}.author_id",
3636
:permission => :view_wiki_edits,
37-
:scope => select("#{table_name}.updated_on, #{table_name}.comments, " +
37+
:scope => proc {
38+
select("#{table_name}.updated_on, #{table_name}.comments, " +
3839
"#{table_name}.version, #{WikiPage.table_name}.title, " +
3940
"#{table_name}.page_id, #{table_name}.author_id, " +
4041
"#{table_name}.id").
4142
joins("LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{table_name}.page_id " +
4243
"LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
4344
"LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id")
45+
}
4446

4547
after_destroy :page_update_after_destroy
4648

extra/sample_plugin/app/models/meeting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ class Meeting < ActiveRecord::Base
77
:url => Proc.new {|o| {:controller => 'meetings', :action => 'show', :id => o.id}}
88

99
acts_as_activity_provider :timestamp => 'scheduled_on',
10-
:scope => includes(:project),
10+
:scope => proc { includes(:project) },
1111
:permission => nil
1212
end

0 commit comments

Comments
 (0)