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
[#50893] Remove n+1 queries
Dombi Attila1117a38a39b2
diff --git a/modules/meeting/app/components/meeting_agenda_items/item_component.rb b/modules/meeting/app/components/meeting_agenda_items/item_component.rbindex 44e1e9792c6..a261f667945 100644--- a/modules/meeting/app/components/meeting_agenda_items/item_component.rb+++ b/modules/meeting/app/components/meeting_agenda_items/item_component.rb@@ -34,13 +34,20 @@ module MeetingAgendaItemswith_collection_parameter :meeting_agenda_item- def initialize(meeting_agenda_item:, state: :show, container: nil, display_notes_input: nil)+ def initialize(+ meeting_agenda_item:,+ state: :show,+ container: nil,+ display_notes_input: nil,+ first_and_last: []+ )super@meeting_agenda_item = meeting_agenda_item@state = state@display_notes_input = display_notes_input@container = container+ @first_and_last = first_and_lastenddef wrapper_uniq_by@@ -51,7 +58,7 @@ module MeetingAgendaItemscomponent_wrapper(:border_box_row, **wrapper_arguments) docase @statewhen :show- render(MeetingAgendaItems::ItemComponent::ShowComponent.new(**child_component_params))+ render(MeetingAgendaItems::ItemComponent::ShowComponent.new(**show_component_params))when :editrender(MeetingAgendaItems::ItemComponent::EditComponent.new(**child_component_params))end@@ -66,7 +73,11 @@ module MeetingAgendaItems{meeting_agenda_item: @meeting_agenda_item,display_notes_input: (@display_notes_input if @state == :edit)- }.compact+ }.compact+ end++ def show_component_params+ child_component_params.merge(first_and_last: @first_and_last).compactenddef wrapper_argumentsdiff --git a/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.rb b/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.rbindex 9802c66ec24..a013a8dfd9f 100644--- a/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.rb+++ b/modules/meeting/app/components/meeting_agenda_items/item_component/show_component.rb@@ -33,11 +33,12 @@ module MeetingAgendaItemsinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- def initialize(meeting_agenda_item:)+ def initialize(meeting_agenda_item:, first_and_last: [])super@meeting_agenda_item = meeting_agenda_item@meeting = meeting_agenda_item.meeting+ @first_and_last = first_and_lastenddef wrapper_uniq_by@@ -54,9 +55,28 @@ module MeetingAgendaItems@meeting.open? && User.current.allowed_in_project?(:manage_agendas, @meeting.project)end+ def first?+ @first ||=+ if @first_and_last.first+ @first_and_last.first == @meeting_agenda_item+ else+ @meeting_agenda_item.first?+ end+ end++ def last?+ @last ||=+ if @first_and_last.last+ @first_and_last.last == @meeting_agenda_item+ else+ @meeting_agenda_item.last?+ end+ end+def meeting_closed?end+def edit_action_item(menu)menu.with_item(label: t("label_edit"),href: edit_meeting_agenda_item_path(@meeting_agenda_item.meeting, @meeting_agenda_item),@@ -78,10 +98,10 @@ module MeetingAgendaItemsenddef move_actions(menu)- move_action_item(menu, :highest, t("label_agenda_item_move_to_top"), "move-to-top") unless @meeting_agenda_item.first?- move_action_item(menu, :higher, t("label_agenda_item_move_up"), "chevron-up") unless @meeting_agenda_item.first?- move_action_item(menu, :lower, t("label_agenda_item_move_down"), "chevron-down") unless @meeting_agenda_item.last?- move_action_item(menu, :lowest, t("label_agenda_item_move_to_bottom"), "move-to-bottom") unless @meeting_agenda_item.last?+ move_action_item(menu, :highest, t("label_agenda_item_move_to_top"), "move-to-top") unless first?+ move_action_item(menu, :higher, t("label_agenda_item_move_up"), "chevron-up") unless first?+ move_action_item(menu, :lower, t("label_agenda_item_move_down"), "chevron-down") unless last?+ move_action_item(menu, :lowest, t("label_agenda_item_move_to_bottom"), "move-to-bottom") unless last?enddef delete_action_item(menu)diff --git a/modules/meeting/app/components/meeting_agenda_items/list_component.html.erb b/modules/meeting/app/components/meeting_agenda_items/list_component.html.erbindex db10ce79e62..76e1fcdd821 100644--- a/modules/meeting/app/components/meeting_agenda_items/list_component.html.erb+++ b/modules/meeting/app/components/meeting_agenda_items/list_component.html.erb@@ -23,10 +23,12 @@endendelse+ first_and_last = [@meeting.agenda_items.first, @meeting.agenda_items.last]render(MeetingAgendaItems::ItemComponent.with_collection(- @meeting.agenda_items,- container: border_box+ @meeting.agenda_items.with_includes_to_render,+ container: border_box,+ first_and_last:))enddiff --git a/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb b/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rbindex e37741c1328..4d65caf4657 100644--- a/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb+++ b/modules/meeting/app/controllers/concerns/meetings/agenda_component_streams.rb@@ -89,9 +89,12 @@ module Meetingsenddef update_show_items_via_turbo_stream(meeting: @meeting)- meeting.agenda_items.each do |meeting_agenda_item|+ agenda_items = meeting.agenda_items.with_includes_to_render+ first_and_last = [agenda_items.first, agenda_items.last]++ agenda_items.each do |meeting_agenda_item|update_via_turbo_stream(- component: MeetingAgendaItems::ItemComponent::ShowComponent.new(meeting_agenda_item:)+ component: MeetingAgendaItems::ItemComponent::ShowComponent.new(meeting_agenda_item:, first_and_last:))endend@@ -136,7 +139,8 @@ module Meetingsreplace_via_turbo_stream(component: MeetingAgendaItems::ItemComponent.new(state:,- meeting_agenda_item:+ meeting_agenda_item:,+ display_notes_input:))update_show_items_via_turbo_streamdiff --git a/modules/meeting/app/models/meeting_agenda_item.rb b/modules/meeting/app/models/meeting_agenda_item.rbindex 3a99d356200..b130005d214 100644--- a/modules/meeting/app/models/meeting_agenda_item.rb+++ b/modules/meeting/app/models/meeting_agenda_item.rb@@ -43,6 +43,8 @@ class MeetingAgendaItem < ApplicationRecordacts_as_list scope: :meetingdefault_scope { order(:position) }+ scope :with_includes_to_render, -> { includes(:author, :meeting) }+validates :meeting_id, presence: truevalidates :title, presence: true, if: Proc.new { |item| item.simple? }validates :work_package_id, presence: true, if: Proc.new { |item| item.work_package? }, on: :creatediff --git a/modules/meeting/app/models/structured_meeting.rb b/modules/meeting/app/models/structured_meeting.rbindex 4cc8d7a4213..84e03b1a17b 100644--- a/modules/meeting/app/models/structured_meeting.rb+++ b/modules/meeting/app/models/structured_meeting.rb@@ -32,11 +32,33 @@ class StructuredMeeting < Meeting# triggered by MeetingAgendaItem#after_create/after_destroy/after_savedef calculate_agenda_item_time_slotscurrent_time = start_time- agenda_items.order(:position).each do |top|- start_time = current_time- current_time += top.duration_in_minutes&.minutes || 0.minutes- end_time = current_time- top.update_columns(start_time:, end_time:) # avoid callbacks, infinite loop otherwise+ MeetingAgendaItem.transaction do+ changed_items = agenda_items.order(:position).map do |top|+ start_time = current_time+ current_time += top.duration_in_minutes&.minutes || 0.minutes+ end_time = current_time+ top.assign_attributes(start_time:, end_time:)+ top+ end++ MeetingAgendaItem.import(+ changed_items,+ on_duplicate_key_update: {+ conflict_target: [:id],+ columns: %i[meeting_id+ author_id+ title+ notes+ position+ duration_in_minutes+ start_time+ end_time+ created_at+ updated_at+ work_package_id+ item_type]+ }+ )endend@@ -45,10 +67,10 @@ class StructuredMeeting < Meetingenddef duration_exceeded_by_agenda_items?- agenda_items_sum_duration_in_minutes > (duration*60 || 0)+ agenda_items_sum_duration_in_minutes > (duration * 60)enddef duration_exceeded_by_agenda_items_in_minutes- agenda_items_sum_duration_in_minutes - (duration*60 || 0)+ agenda_items_sum_duration_in_minutes - (duration * 60)endenddiff --git a/modules/meeting/spec/models/meeting_acts_as_journalized_spec.rb b/modules/meeting/spec/models/meeting_acts_as_journalized_spec.rbindex 8f21e9648eb..c0e5df9e411 100644--- a/modules/meeting/spec/models/meeting_acts_as_journalized_spec.rb+++ b/modules/meeting/spec/models/meeting_acts_as_journalized_spec.rb@@ -280,7 +280,7 @@ RSpec.describe Meeting dodescribe '#destroy' dobefore do- meeting.agenda_items << create(:meeting_agenda_item)+ meeting.agenda_items << build(:meeting_agenda_item)meeting.saveend