def self.load_visible_last_updated_by(issues, user=User.current)
if issues.any?
issue_ids = issues.map(&:id)
- journals = Journal.joins(issue: :project).preload(:user).
+ journal_ids = Journal.joins(issue: :project).
where(:journalized_type => 'Issue', :journalized_id => issue_ids).
- where("#{Journal.table_name}.id = (SELECT MAX(j.id) FROM #{Journal.table_name} j" +
- " WHERE j.journalized_type='Issue' AND j.journalized_id=#{Journal.table_name}.journalized_id" +
- " AND #{Journal.visible_notes_condition(user, :skip_pre_condition => true)})").to_a
+ where(Journal.visible_notes_condition(user, :skip_pre_condition => true)).
+ group(:journalized_id).
+ maximum(:id).
+ values
+ journals = Journal.where(:id => journal_ids).to_a
issues.each do |issue|
journal = journals.detect {|j| j.journalized_id == issue.id}
def self.load_visible_last_notes(issues, user=User.current)
if issues.any?
issue_ids = issues.map(&:id)
- journals = Journal.joins(issue: :project).
+ journal_ids = Journal.joins(issue: :project).
where(:journalized_type => 'Issue', :journalized_id => issue_ids).
- where("#{Journal.table_name}.id = (SELECT MAX(j.id) FROM #{Journal.table_name} j" +
- " WHERE j.journalized_type='Issue' AND j.journalized_id=#{Journal.table_name}.journalized_id" +
- " AND j.notes <> ''" +
- " AND #{Journal.visible_notes_condition(user, :skip_pre_condition => true)})").to_a
+ where(Journal.visible_notes_condition(user, :skip_pre_condition => true)).
+ where.not(notes: '').
+ group(:journalized_id).
+ maximum(:id).
+ values
+ journals = Journal.where(:id => journal_ids).to_a
issues.each do |issue|
journal = journals.detect {|j| j.journalized_id == issue.id}
end
def test_index_with_last_notes_column_should_display_private_notes_with_permission_only
+ journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Public notes', :user_id => 1)
journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
@request.session[:user_id] = 2
get :index, :set_filter => 1, :c => %w(subject last_notes)
assert_response :success
- assert_select 'td.last_notes[colspan="3"]', :text => 'A comment with inline image: and a reference to #1 and r2.'
+ assert_select 'td.last_notes[colspan="3"]', :text => 'Public notes'
end
def test_index_with_description_and_last_notes_columns_should_display_column_name