mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
only write to db if is_default value has changed
This commit is contained in:
parent
3349edda89
commit
b99fb686dd
1 changed files with 16 additions and 8 deletions
|
|
@ -72,14 +72,22 @@ def _choose_cheapest_relevant_plan(plans: List[Plan]) -> Plan:
|
|||
return cheapest_plan
|
||||
|
||||
|
||||
def _update_default_flags(plans: List[Plan], cheapest_plan: Plan) -> None:
|
||||
plan_models: List[PlanModel] = []
|
||||
scenario_models: List[ScenarioModel] = []
|
||||
def _update_default_flags(plans: List["Plan"], cheapest_plan: Plan) -> None:
|
||||
plans_to_update: List[Plan] = []
|
||||
|
||||
for plan in plans:
|
||||
plan.set_default(plan.id == cheapest_plan.id)
|
||||
plan_model, scenario_model = plan.to_sqlalchemy()
|
||||
plan_models.append(plan_model)
|
||||
scenario_models.append(scenario_model)
|
||||
should_be_default: bool = plan.id == cheapest_plan.id
|
||||
if plan.record.is_default != should_be_default:
|
||||
plan.set_default(should_be_default)
|
||||
plans_to_update.append(plan)
|
||||
|
||||
bulk_update_plans(plan_models, scenario_models)
|
||||
if plans_to_update:
|
||||
plan_models: List[PlanModel] = []
|
||||
scenario_models: List[ScenarioModel] = []
|
||||
|
||||
for plan in plans_to_update:
|
||||
plan_model, scenario_model = plan.to_sqlalchemy()
|
||||
plan_models.append(plan_model)
|
||||
scenario_models.append(scenario_model)
|
||||
|
||||
bulk_update_plans(plan_models, scenario_models)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue