-
Notifications
You must be signed in to change notification settings - Fork 646
Open
Description
I was debugging the performance of a large query serialisation (read query) , and I stumbled upon something curious. There is significant amount of time being spent in AASM::Persistence::ActiveRecordPersistence.
Upon investigation, it seems that most of the time is being spent on attribute models. It seems to be coming from aasm_ensure_initial_state and aasm_column_is_blank, listing all attribute names.
I found a comment that this method is not using responds_to because of Rails 3 support. Given that it has been 10 years, I wonder if it we could consider migrating to responds_to, and if it would make it a bit more performant? After all in our case, we only have one AASM field in a very large model.
def aasm_ensure_initial_state
AASM::StateMachineStore.fetch(self.class, true).machine_names.each do |state_machine_name|
# checking via respond_to? does not work in Rails <= 3
# if respond_to?(self.class.aasm(state_machine_name).attribute_name) && send(self.class.aasm(state_machine_name).attribute_name).blank? # Rails 4
if aasm_column_is_blank?(state_machine_name)
aasm(state_machine_name).enter_initial_state
end
end
end
def aasm_column_is_blank?(state_machine_name)
attribute_name = self.class.aasm(state_machine_name).attribute_name
attribute_names.include?(attribute_name.to_s) &&
(send(attribute_name).respond_to?(:empty?) ? !!send(attribute_name).empty? : !send(attribute_name))
endpernambucano and joshshifman
Metadata
Metadata
Assignees
Labels
No labels