From c63210a7ae642ee47f90f29ffddce4f7f0423469 Mon Sep 17 00:00:00 2001 From: casulit Date: Wed, 30 Oct 2024 08:44:12 +0800 Subject: [PATCH] refactor(deno-kv): Use client2 for DB queries instead of transaction --- config/deno-kv.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/config/deno-kv.ts b/config/deno-kv.ts index 580f310..95cce7d 100644 --- a/config/deno-kv.ts +++ b/config/deno-kv.ts @@ -131,7 +131,7 @@ export async function listenQueue(kv: Deno.Kv) { await transaction.begin(); - const rawPropertiesCount = await transaction.queryObject< + const rawPropertiesCount = await client2.queryObject< { count: number } >({ text: ` @@ -145,7 +145,7 @@ export async function listenQueue(kv: Deno.Kv) { `Processing ${rawPropertiesCount.rows[0].count} raw properties`, ); - const rawProperties = await transaction.queryObject( + const rawProperties = await client2.queryObject( ` SELECT id, @@ -365,7 +365,7 @@ export async function listenQueue(kv: Deno.Kv) { if (listingByUrl.rowCount && listingByUrl.rowCount > 0) { console.info("Listing query by url already exists"); - const updateListingResult = await transaction.queryObject({ + const updateListingResult = await client2.queryObject({ args: [ rawProperty.price, rawProperty.price_formatted, @@ -384,7 +384,7 @@ export async function listenQueue(kv: Deno.Kv) { ); } - const updatePropertyResult = await transaction.queryObject({ + const updatePropertyResult = await client2.queryObject({ args: [ JSON.stringify(images), rawProperty.agent_name, @@ -409,7 +409,7 @@ export async function listenQueue(kv: Deno.Kv) { ); } - const updateResult = await transaction.queryObject({ + const updateResult = await client2.queryObject({ args: [rawProperty.id], text: ` UPDATE lamudi_raw_data @@ -439,9 +439,7 @@ export async function listenQueue(kv: Deno.Kv) { }); if (listingByTitle.rowCount && listingByTitle.rowCount > 0) { - await transaction.commit() console.info("Listing query by title already exists") - console.info("Transaction successfully committed"); return; } @@ -468,7 +466,7 @@ export async function listenQueue(kv: Deno.Kv) { throw error; } - property = await client2.queryObject({ + property = await transaction.queryObject({ args: [ lastCreatedPropertyId, rawProperty.floor_size,