From 793dc22991d724e0f335d79c3391b28107d7ab09 Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 23 Jul 2024 10:36:08 +0200 Subject: [PATCH] Speedup generating of storage locations tree for move modal [SCI-10863] --- app/controllers/storage_locations_controller.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 30a7f3328..ee3c9ed90 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -78,10 +78,8 @@ class StorageLocationsController < ApplicationController end def tree - records = StorageLocation.inner_storage_locations(current_team) - .order(:name) - .select(:id, :name, :parent_id, :container) - render json: storage_locations_recursive_builder(nil, records) + records = current_team.storage_locations.where(parent: nil, container: false) + render json: storage_locations_recursive_builder(records) end def actions_toolbar @@ -151,11 +149,11 @@ class StorageLocationsController < ApplicationController } end - def storage_locations_recursive_builder(parent_storage_location, records) - records.where(parent: parent_storage_location, container: false).map do |storage_location| + def storage_locations_recursive_builder(storage_locations) + storage_locations.map do |storage_location| { storage_location: storage_location, - children: storage_locations_recursive_builder(storage_location, records) + children: storage_locations_recursive_builder(storage_location.storage_locations.where(container: false)) } end end