@@ -207,51 +207,17 @@ async def sync(
207207 _print ("No new data fetched" , quiet = quiet )
208208 else :
209209 _print ("Inserting plan data..." , quiet = quiet )
210- await insert_plans (context , plans , new_lkos )
211- await asyncio .gather (
212- * (
213- insert_accounts (context , plan_id , account_data ["accounts" ], quiet )
214- for plan_id , account_data in zip (
215- plan_ids , all_account_data , strict = True
216- )
217- ),
218- * (
219- insert_category_groups (
220- context ,
221- plan_id ,
222- cat_data ["category_groups" ],
223- quiet ,
224- )
225- for plan_id , cat_data in zip (plan_ids , all_cat_data , strict = True )
226- ),
227- * (
228- insert_payees (context , plan_id , payee_data ["payees" ], quiet )
229- for plan_id , payee_data in zip (
230- plan_ids , all_payee_data , strict = True
231- )
232- ),
233- )
234- await asyncio .gather (
235- * (
236- insert_transactions (
237- context ,
238- plan_id ,
239- txn_data ["transactions" ],
240- quiet ,
241- )
242- for plan_id , txn_data in zip (plan_ids , all_txn_data , strict = True )
243- ),
244- * (
245- insert_scheduled_transactions (
246- context ,
247- plan_id ,
248- sched_txn_data ["scheduled_transactions" ],
249- quiet ,
250- )
251- for plan_id , sched_txn_data in zip (
252- plan_ids , all_sched_txn_data , strict = True
253- )
254- ),
210+ await insert_plan_data (
211+ context ,
212+ plans ,
213+ plan_ids ,
214+ all_account_data ,
215+ all_cat_data ,
216+ all_payee_data ,
217+ all_txn_data ,
218+ all_sched_txn_data ,
219+ new_lkos ,
220+ quiet ,
255221 )
256222 await context .con .commit ()
257223 _print ("Done" , quiet = quiet )
@@ -275,6 +241,67 @@ async def get_last_knowledge_of_server(cur: aiosqlite.Cursor) -> dict[str, int]:
275241 return {r ["id" ]: r ["last_knowledge_of_server" ] for r in await cur .fetchall ()}
276242
277243
244+ async def insert_plan_data (
245+ context : _Context ,
246+ plans : list [dict [str , Any ]],
247+ plan_ids : list [str ],
248+ all_account_data : list [dict [str , Any ]],
249+ all_cat_data : list [dict [str , Any ]],
250+ all_payee_data : list [dict [str , Any ]],
251+ all_txn_data : list [dict [str , Any ]],
252+ all_sched_txn_data : list [dict [str , Any ]],
253+ new_lkos : dict [str , int ],
254+ quiet : bool ,
255+ ) -> None :
256+ await insert_plans (context , plans , new_lkos )
257+ await asyncio .gather (
258+ * (
259+ insert_accounts (
260+ context ,
261+ plan_id ,
262+ account_data ["accounts" ],
263+ quiet ,
264+ )
265+ for plan_id , account_data in zip (plan_ids , all_account_data , strict = True )
266+ ),
267+ * (
268+ insert_category_groups (
269+ context ,
270+ plan_id ,
271+ cat_data ["category_groups" ],
272+ quiet ,
273+ )
274+ for plan_id , cat_data in zip (plan_ids , all_cat_data , strict = True )
275+ ),
276+ * (
277+ insert_payees (context , plan_id , payee_data ["payees" ], quiet )
278+ for plan_id , payee_data in zip (plan_ids , all_payee_data , strict = True )
279+ ),
280+ )
281+ await asyncio .gather (
282+ * (
283+ insert_transactions (
284+ context ,
285+ plan_id ,
286+ txn_data ["transactions" ],
287+ quiet ,
288+ )
289+ for plan_id , txn_data in zip (plan_ids , all_txn_data , strict = True )
290+ ),
291+ * (
292+ insert_scheduled_transactions (
293+ context ,
294+ plan_id ,
295+ sched_txn_data ["scheduled_transactions" ],
296+ quiet ,
297+ )
298+ for plan_id , sched_txn_data in zip (
299+ plan_ids , all_sched_txn_data , strict = True
300+ )
301+ ),
302+ )
303+
304+
278305async def insert_plans (
279306 context : _Context , plans : list [dict [str , Any ]], lkos : dict [str , int ]
280307) -> None :
0 commit comments