I have rails app where I have multiple models. Such as model Input with following associations :-
belongs_to :department, :class_name => 'Department'
has_many :frame_inputs, class_name: 'Frames::FrameInput', foreign_key: 'input_id', :dependent => :destroy
has_many :frames, :through => :frame_inputs, :class_name => 'Frames::Base'
has_many :scales, :foreign_key => :input_id, :dependent => :destroy
has_many :input_items, :class_name => 'InputItems::Base', :foreign_key => :department_id, :dependent => :destroy
has_many :linenumbers, :class_name => 'Frames::InputItemPriority', :through => :input_items
Challenge:- Whenever trying to delete an Input record from the application, the backend Active record query takes lot of time, i.e. 10 - 20 seconds for completing one single transaction.
Question:- As, it has to destroy all the record dependencies, can I reduce the transaction time for executing the delete/destroy query ?
For destroying the records I have following method in my Inputs controller
def destroy
@input.destroy
end
Please guide me on how to optimize the destroy query to reduce the transaction time.
Thanks