Skip to content

Commit

Permalink
refactor(config): Reorder update queries for better transaction flow
Browse files Browse the repository at this point in the history
  • Loading branch information
csulit committed Oct 29, 2024
1 parent 776881c commit 14cb41e
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions config/deno-kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
}

Expand Down

0 comments on commit 14cb41e

Please sign in to comment.