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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Merge branch 'dev' into implementation/45980-improve-performance-of-baseline-filtering
ulferts25d9c53a892e
diff --cc app/services/journals/create_service.rbindex 4afa3a8f183,a37ca9555f7..5a831587567--- a/app/services/journals/create_service.rb+++ b/app/services/journals/create_service.rb@@@ -378,73 -383,30 +390,97 @@@ module Journaljournable_class_name:)end+ def insert_storable_sql+ storable_sql = <<~SQL+ INSERT INTO+ storages_file_links_journals (+ journal_id,+ file_link_id,+ link_name+ )+ SELECT+ #{id_from_inserted_journal_sql},+ file_links.id,+ file_links.origin_name+ FROM file_links+ WHERE+ #{only_if_created_sql}+ AND file_links.container_id = :journable_id+ AND file_links.container_type = :journable_class_name+ SQL++ sanitize(storable_sql,+ journable_id: journable.id,+ journable_class_name:)+ end++ # Updates the updated_at timestamp of the journable.+ # That is only carried out if the journable doesn't already have a newer timestamp than the most recent journal.+ # Most recent in this case can mean one of two things:+ # * if there is a predecessor we are aggregating with, it is that predecessor+ # * otherwise, the most recent journal that we are not aggregating with.+ # Whenever an attribute is updated on the journable before creating the journal, the udpated_at timestamp+ # will already have been increased so nothing needs to be done.+ # But if any of the associated data is updated or if only a cause or note is added, the journable would+ # otherwise not have receive an updated timestamp.+ # There is a special case if the updated_at of the journable is itself updated. In such a case, that value is used.+ def touch_journable_sql(predecessor, notes, cause)+ if journable.class.aaj_options[:timestamp].to_sym == :updated_at+ update_sql = <<~SQL+ UPDATE+ #{journable_table_name}+ SET+ updated_at = COALESCE(:update_timestamp, statement_timestamp())+ WHERE+ id = :id+ #{only_on_changed_or_forced_condition_sql(predecessor, notes, cause)}+ AND NOT updated_at > COALESCE(:predecessor_timestamp, (SELECT updated_at FROM max_journals))+ RETURNING updated_at+ SQL++ sanitize(update_sql,+ update_timestamp: journable.updated_at_previously_changed? ? journable.updated_at : nil,+ predecessor_timestamp: predecessor&.updated_at,+ id: journable.id)+ else+ <<~SQL+ SELECT NULL::timestamp with time zone AS updated_at+ SQL+ end+ end++ # Fetches the timestamp to be used by all subsequent SQL statements e.g. for+ # * setting the created_at and updated_at timestamps of the newly created journal+ # * setting the updated_at timestamp on an updated (aggregated with) journal+ # * setting the validity_period (upper bound) of the preceding journal.+ def fetch_time_sql+ update_sql = <<~SQL+ SELECT COALESCE((SELECT updated_at FROM touch_journable), :journable_timestamp) AS updated_at+ SQL++ sanitize(update_sql,+ journable_timestamp:)+ end++ # Sets the validity_period's upper boundary of the preceding journal to the created_at timestamp of the inserted journal.+ # The upper bound set is not included.+ # If there is a predecessor (meaning we are aggregating/updating an existing journal), nothing is done since+ # in that case the preceding journal is the one we are currently aggregating with so it will still remain+ # the most recent one.+ def update_predecessor_sql(predecessor, notes, cause)+ return "SELECT 1" if predecessor.present?++ <<~SQL+ UPDATE+ journals+ SET+ validity_period = tstzrange(lower(validity_period), (SELECT updated_at FROM fetch_time), '[)')+ WHERE+ id = (SELECT id from max_journals)+ #{only_on_changed_or_forced_condition_sql(predecessor, notes, cause)}+ SQL+ end+def select_max_journal_sql(predecessor)sql = <<~SQLSELECTdiff --cc spec/features/work_packages/tabs/activity_tab_spec.rbindex c9011f90360,69b284706a7..e2611a114e3--- a/spec/features/work_packages/tabs/activity_tab_spec.rb+++ b/spec/features/work_packages/tabs/activity_tab_spec.rb@@@ -33,24 -33,39 +33,39 @@@ require 'support/edit_fields/edit_fieldRSpec.describe 'Activity tab',js: true,- selenium: true do- def alter_work_package_at(work_package, attributes:, at:, user: User.current)- work_package.custom_field_values = attributes.delete(:custom_field_values)- work_package.update(attributes.merge(updated_at: at))-- note_journal = work_package.journals.last- note_journal.update(created_at: at, updated_at: at, user:)+ with_cuprite: true do- let(:project) { create(:project_with_types, public: true) }++ let(:project) do++ create(:project_with_types,++ types: [type_with_cf],++ work_package_custom_fields: [string_cf],++ public: true)+ end++ let(:string_cf) { create(:text_wp_custom_field) }++ let(:type_with_cf) do+ create(:type, custom_fields: [string_cf])+ end- let(:project) do- create(:project_with_types,- types: [type_with_cf],- work_package_custom_fields: [string_cf],- public: true)- end+ let(:creation_time) { 5.days.ago }+ let(:subject_change_time) { 3.days.ago }+ let(:revision_time) { 2.days.ago }+ let(:comment_time) { 1.day.ago }let!(:work_package) do- work_package = create(:work_package,- project:,- created_at: 5.days.ago.to_date.to_fs(:db),- subject: initial_subject,- journal_notes: initial_comment)-- note_journal = work_package.journals.reload.last- note_journal.update(created_at: 5.days.ago.to_date.to_s, updated_at: 5.days.ago.to_date.to_s)-- work_package+ create(:work_package,+ project:,+ created_at: creation_time,+ subject: initial_subject,+ journals: {+ creation_time => { notes: initial_comment },+ subject_change_time => { subject: 'New subject', description: 'Some not so long description.' },+ comment_time => { notes: 'A comment by a different user', user: create(:admin) }- })++ }).tap do |wp|++ Journal::CustomizableJournal.create!(journal: wp.journals[1],++ custom_field_id: string_cf.id,++ value: "* [x] Task 1\n* [ ] Task 2")++ endendlet(:initial_subject) { 'My Subject' }