From 14cb41e340b13cb8aee6c0eb7f338fd7940a10c3 Mon Sep 17 00:00:00 2001 From: casulit Date: Wed, 30 Oct 2024 06:58:03 +0800 Subject: [PATCH] refactor(config): Reorder update queries for better transaction flow --- config/deno-kv.ts | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/config/deno-kv.ts b/config/deno-kv.ts index 9060b13..f9cfd47 100644 --- a/config/deno-kv.ts +++ b/config/deno-kv.ts @@ -365,26 +365,11 @@ export async function listenQueue(kv: Deno.Kv) { if (listing.rowCount && listing.rowCount > 0) { console.info("Listing already exists"); - const updateResult = await transaction.queryObject({ - args: [rawProperty.id], - text: ` - UPDATE lamudi_raw_data - SET is_process = TRUE - WHERE id = $1 - `, - }); - - if (updateResult.rowCount === 1) { - console.info("1 record updated in lamudi_raw_data"); - } - - - const updateListingResult = await transaction.queryObject({ args: [ rawProperty.price, rawProperty.price_formatted, - listing.rows[0].id + listing.rows[0].id, ], text: ` UPDATE Listing @@ -405,7 +390,7 @@ export async function listenQueue(kv: Deno.Kv) { rawProperty.agent_name, rawProperty.product_owner_name, rawProperty.project_name, - listing.rows[0].property_id + listing.rows[0].property_id, ], text: ` UPDATE Property p @@ -424,6 +409,19 @@ export async function listenQueue(kv: Deno.Kv) { ); } + const updateResult = await transaction.queryObject({ + args: [rawProperty.id], + text: ` + UPDATE lamudi_raw_data + SET is_process = TRUE + WHERE id = $1 + `, + }); + + if (updateResult.rowCount === 1) { + console.info("1 record updated in lamudi_raw_data"); + } + continue; }