8000 Refactor handling of `c.option_list.empty?` · DMPRoadmap/roadmap@82984e2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 82984e2

Browse files
committed
Refactor handling of c.option_list.empty?
- Moved `c.option_list.empty?` immediately after `c.option_list` assignment to streamline logic. - This change reduces unnecessary processing of `c.remove_data` and `c.webhook_data`. - Isolating the `c.option_list.empty?` check also simplifies subsequent checks for `c.remove_data.empty?` and c.webhook_data.nil?` later in the code.
1 parent f6a232b commit 82984e2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

app/models/question.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,24 @@ def save_condition(value, opt_map, question_id_map)
222222
# question options may have changed so rewrite them
223223
c.option_list = value['question_option']
224224
c.option_list = c.option_list.map { |qopt| opt_map[qopt] } if opt_map.present?
225+
# Do not save the condition if the option_list is empty
226+
if c.option_list.empty?
227+
c.destroy
228+
return
229+
end
225230

226231
if value['action_type'] == 'remove'
227232
c.remove_data = value['remove_question_id']
228233
c.remove_data = c.remove_data.map { |qid| question_id_map[qid] } if question_id_map.present?
229-
230-
# Do not save the condition if the option_list or remove_data is empty
231-
if c.option_list.empty? || c.remove_data.empty?
234+
# Do not save the condition if remove_data is empty
235+
if c.remove_data.empty?
232236
c.destroy
233237
return
234238
end
235239
else
236240
c.webhook_data = handle_webhook_data(value)
237-
238-
# Do not save the condition if the option_list is empty or webhook_data is nil
239-
if c.option_list.empty? || c.webhook_data.nil?
241+
# Do not save the condition if webhook_data is nil
242+
if c.webhook_data.nil?
240243
c.destroy
241244
return
242245
end

0 commit comments

Comments
 (0)
0