From eaff5d9f5b616d518ec331f807e0f24daa4af054 Mon Sep 17 00:00:00 2001 From: Christopher Aitken Date: Sat, 21 Sep 2024 23:19:34 -0500 Subject: [PATCH] Removed userId association from messages/tags, using dev scan on staging --- src/internal/processScans.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/internal/processScans.ts b/src/internal/processScans.ts index cd685d5..4450269 100644 --- a/src/internal/processScans.ts +++ b/src/internal/processScans.ts @@ -1,4 +1,5 @@ -import { chunk, db, sleep } from '#src/utils'; +import { chunk, db, isStaging, sleep } from '#src/utils'; +import { hashStringToUuid } from '#src/utils/hashStringToUuid'; export const processScans = async (event) => { console.log(`START PROCESS SCANS`); @@ -18,7 +19,7 @@ export const processScans = async (event) => { console.log(`Start ${index} of ${batchesOfJobIds.length} batches`); await Promise.allSettled(batchOfJobIds.map(jobId => new Promise(async (res) => { try { - const scanResults = await fetch(`https://scan.equalify.app/results/${jobId}`, { signal: AbortSignal.timeout(10000) }); + const scanResults = await fetch(`https://scan${isStaging ? '-dev' : ''}.equalify.app/results/${jobId}`, { signal: AbortSignal.timeout(10000) }); const { result, status } = await scanResults.json(); if (['delayed', 'active', 'waiting'].includes(status)) { remainingScans.push(jobId); @@ -156,25 +157,27 @@ const scanProcessor = async ({ result, jobId, userId, propertyId }) => { } } for (const row of result.tags) { + const tagId = hashStringToUuid(row.tag); row.id = (await db.query({ - text: `SELECT "id" FROM "tags" WHERE "user_id"=$1 AND "tag"=$2`, - values: [userId, row.tag], + text: `SELECT "id" FROM "tags" WHERE "tag"=$1`, + values: [tagId], })).rows?.[0]?.id ?? (await db.query({ - text: `INSERT INTO "tags" ("user_id", "tag") VALUES ($1, $2) RETURNING "id"`, - values: [userId, row.tag], + text: `INSERT INTO "tags" ("id", "tag") VALUES ($1, $2) RETURNING "id"`, + values: [tagId, row.tag], })).rows?.[0]?.id; } for (const row of result.messages) { + const messageId = hashStringToUuid(row.message); row.id = (await db.query({ - text: `SELECT "id" FROM "messages" WHERE "user_id"=$1 AND "message"=$2 AND "type"=$3`, - values: [userId, row.message, row.type], + text: `SELECT "id" FROM "messages" WHERE "id"=$1`, + values: [messageId], })).rows?.[0]?.id ?? (await db.query({ - text: `INSERT INTO "messages" ("user_id", "message", "type") VALUES ($1, $2, $3) RETURNING "id"`, - values: [userId, row.message, row.type], + text: `INSERT INTO "messages" ("id", "message", "type") VALUES ($1, $2, $3) RETURNING "id"`, + values: [messageId, row.message, row.type], })).rows?.[0]?.id; for (const relatedNodeId of row.relatedNodeIds) {