Skip to content

Commit

Permalink
perf(bulk_routing): make less requests when bulk_routing
Browse files Browse the repository at this point in the history
  • Loading branch information
E-L-T committed Mar 4, 2025
1 parent a0dc47e commit 6216f3c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,15 @@ def export_groupe_instructeurs
end

def bulk_route
dossiers = procedure.dossiers.state_not_termine
dossiers = procedure.dossiers.includes(:procedure, :groupe_instructeur, :champs, revision: [:types_de_champ]).state_not_termine

Check warning on line 401 in app/controllers/administrateurs/groupe_instructeurs_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/groupe_instructeurs_controller.rb#L401

Added line #L401 was not covered by tests

dossiers.update_all(forced_groupe_instructeur: false)

Check warning on line 403 in app/controllers/administrateurs/groupe_instructeurs_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/groupe_instructeurs_controller.rb#L403

Added line #L403 was not covered by tests

dossiers.each do |dossier|
RoutingEngine.compute(dossier, assignment_mode: DossierAssignment.modes.fetch(:bulk_routing))
dossiers.in_batches do |relation|
relation.each do |dossier|
RoutingEngine.compute(dossier, assignment_mode: DossierAssignment.modes.fetch(:bulk_routing))

Check warning on line 407 in app/controllers/administrateurs/groupe_instructeurs_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/groupe_instructeurs_controller.rb#L405-L407

Added lines #L405 - L407 were not covered by tests
end
end

procedure.update!(routing_alert: false)

Check warning on line 410 in app/controllers/administrateurs/groupe_instructeurs_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/groupe_instructeurs_controller.rb#L410

Added line #L410 was not covered by tests

flash[:notice] = "Les dossiers ont étés routés vers les groupes d’instructeurs"

Check warning on line 412 in app/controllers/administrateurs/groupe_instructeurs_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/administrateurs/groupe_instructeurs_controller.rb#L412

Added line #L412 was not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion app/models/dossier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def show_procedure_state_warning?

def assign_to_groupe_instructeur(groupe_instructeur, mode, author = nil)
return if groupe_instructeur.present? && groupe_instructeur.procedure != procedure
return if self.groupe_instructeur == groupe_instructeur
return if self.groupe_instructeur == groupe_instructeur && mode == self.dossier_assignment&.mode

previous_groupe_instructeur = self.groupe_instructeur

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1110,13 +1110,20 @@ def remove_instructeur(instructeur)
dossier2.champs.first.update(value: 'Lyon')
dossier3.champs.first.update(value: 'Marseille')
post :create_simple_routing, params: { procedure_id: procedure.id, create_simple_routing: { stable_id: drop_down_tdc.stable_id } }
post :bulk_route, params: { procedure_id: procedure.id }
end

it 'routes only dossiers en construction or en instruction' do
query_count = 0
ActiveSupport::Notifications.subscribed(lambda { |*_args| query_count += 1 }, "sql.active_record") do
post :bulk_route, params: { procedure_id: procedure.id }
end
expect(query_count).to be_between(60, 90)
expect(dossier1.reload.groupe_instructeur.label).to eq 'Paris'
expect(dossier1.reload.dossier_assignment.mode).to eq 'bulk_routing'
expect(dossier2.reload.groupe_instructeur.label).to eq 'Lyon'
expect(dossier2.reload.dossier_assignment.mode).to eq 'bulk_routing'
expect(dossier3.reload.groupe_instructeur.label).to eq 'Lyon'
expect(dossier3.reload.dossier_assignment.mode).to eq 'auto'
# Lyon is default group
expect(procedure.reload.routing_alert).to be_falsey
end
Expand Down

0 comments on commit 6216f3c

Please sign in to comment.