Skip to content

Commit

Permalink
Removed userId association from messages/tags, using dev scan on staging
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisischris committed Sep 22, 2024
1 parent 6cc56cf commit eaff5d9
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/internal/processScans.ts
Original file line number Diff line number Diff line change
@@ -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`);
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit eaff5d9

Please sign in to comment.