Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Use distinct(*) on aggregated journal to avoid duplicate raw journals

Oliver Günthera92575e3ec02
diff --git a/app/models/journal/aggregated_journal.rb b/app/models/journal/aggregated_journal.rb
index a1955ea6d66..dc70b7548a5 100644
--- a/app/models/journal/aggregated_journal.rb
+++ b/app/models/journal/aggregated_journal.rb
@@ -63,7 +63,9 @@ class Journal::AggregatedJournal
# The +until_version+ parameter can be used in conjunction with the +journable+ parameter
# to see the aggregated journals as if no versions were known after the specified version.
def aggregated_journals(journable: nil, sql: nil, until_version: nil, includes: [])
- raw_journals = Journal::Scopes::AggregatedJournal.fetch(journable: journable, sql: sql, until_version: until_version)
+ raw_journals = Journal::Scopes::AggregatedJournal
+ .fetch(journable: journable, sql: sql, until_version: until_version)
+ .order('version ASC')
aggregated_journals = map_to_aggregated_journals(raw_journals)
preload_associations(journable, aggregated_journals, includes)
diff --git a/app/models/journal/scopes/aggregated_journal.rb b/app/models/journal/scopes/aggregated_journal.rb
index b7801b28357..e4878dcef1b 100644
--- a/app/models/journal/scopes/aggregated_journal.rb
+++ b/app/models/journal/scopes/aggregated_journal.rb
@@ -41,6 +41,7 @@ module Journal::Scopes
# having to also use a CASE/COALESCE statement.
Journal
.from(select_sql(journals_preselection))
+ .select("DISTINCT *")
end
private
diff --git a/spec/features/work_packages/details/markdown/activity_comments_spec.rb b/spec/features/work_packages/details/markdown/activity_comments_spec.rb
index 243617b249e..69ac7f77ce9 100644
--- a/spec/features/work_packages/details/markdown/activity_comments_spec.rb
+++ b/spec/features/work_packages/details/markdown/activity_comments_spec.rb
@@ -68,6 +68,34 @@ describe 'activity comments', js: true, with_mail: false do
expect(page).to have_selector('.user-comment > .message', count: 3)
wp_page.expect_comment text: 'this is my second comment!1'
+
+ expect(comment_field.editing?).to be false
+ comment_field.activate!
+ expect(comment_field.editing?).to be true
+
+ comment_field.click_and_type_slowly 'this is my third comment!1'
+ comment_field.submit_by_click
+
+ # Only shows three most recent
+ expect(page).to have_selector('.user-comment > .message', count: 3)
+ wp_page.expect_comment text: 'this is my third comment!1'
+
+ wp_page.switch_to_tab tab: 'Activity'
+ # Now showing all comments
+ expect(page).to have_selector('.user-comment > .message', count: 4, wait: 10)
+
+ expect(comment_field.editing?).to be false
+ comment_field.activate!
+ expect(comment_field.editing?).to be true
+
+ comment_field.click_and_type_slowly 'this is my fifth comment!1'
+ comment_field.submit_by_click
+
+ expect(page).to have_selector('.user-comment > .message', count: 4)
+ wp_page.expect_comment text: 'this is my fifth comment!1'
+
+ # Expect no activity details
+ expect(page).to have_no_selector('.work-package-details-activities-messages li')
end
end