From 79ff7322029f6f623381ed1b0ac0826ef39a91bc Mon Sep 17 00:00:00 2001 From: Nick Scialli <7538045+nas5w@users.noreply.github.com> Date: Sat, 19 Apr 2025 13:53:25 -0400 Subject: [PATCH] Backfill only allowed extensions, for now --- projects/plc-backfill/backfill.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/projects/plc-backfill/backfill.ts b/projects/plc-backfill/backfill.ts index 22ce66c..ec46f08 100644 --- a/projects/plc-backfill/backfill.ts +++ b/projects/plc-backfill/backfill.ts @@ -1,14 +1,24 @@ import { PlcAgent, PlcRecord } from "./plcAgent"; import { GovskyPrismaClient } from "@govsky/database"; +import { allowedExtensions } from "@govsky/config"; const prisma = new GovskyPrismaClient(); const LATEST_RECORD_SETTING_KEY = "latestRecord"; async function addHandles(records: PlcRecord[], latestRecord: Date) { - if (records.length) { + console.log(`Finding matches for domains: ${allowedExtensions.join(", ")}`); + const matchingRecords = records.filter((record) => { + return allowedExtensions.some((ext) => + record.handle.toLowerCase().endsWith(ext.toLowerCase()) + ); + }); + + console.log(`Matching records: ${matchingRecords.length}`); + + if (matchingRecords.length) { await prisma.user.createMany({ - data: records.map((record) => { + data: matchingRecords.map((record) => { const handleParts = record.handle.split("."); const handlePart1 = handleParts.pop() || ""; const handlePart2 = handleParts.pop() || ""; @@ -50,7 +60,8 @@ export async function backfill() { plcAgent.startExport( (data) => { - console.log(data.latestRecord, data.records.length); + console.log(`Latest record: ${data.latestRecord}`); + console.log(`Total records: ${data.records.length}`); addHandles(data.records, data.latestRecord).catch((e) => { console.error("Failed adding handles", e); });