feat: implement character changes page with new and modified character listings
All checks were successful
Build Docker Image / build (push) Successful in 1m23s
All checks were successful
Build Docker Image / build (push) Successful in 1m23s
This commit is contained in:
@@ -327,8 +327,8 @@ async function importFromJson(): Promise<void> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Check for changes and update scrapeValidation table
|
||||
console.log('Characters table not empty, checking for changes...\n');
|
||||
// Update scrapeValidation table
|
||||
console.log('Characters table not empty, updating scrapeValidation table for changes...\n');
|
||||
|
||||
for (let i = 0; i < characters.length; i++) {
|
||||
const item = characters[i];
|
||||
@@ -340,33 +340,19 @@ async function importFromJson(): Promise<void> {
|
||||
.where(eq(character.id, item.id));
|
||||
|
||||
lastSql = selectQuery.toSQL();
|
||||
const [dbCharacter] = await selectQuery;
|
||||
|
||||
const jsonData = transformCharacterData(item);
|
||||
const changed = hasChanged(jsonData, dbCharacter);
|
||||
|
||||
if (changed) {
|
||||
// Update scrapeValidation table with changes
|
||||
const upsertQuery = db
|
||||
.insert(characterScrapeValidation)
|
||||
.values(jsonData)
|
||||
.onConflictDoUpdate({
|
||||
target: characterScrapeValidation.id,
|
||||
set: jsonData
|
||||
});
|
||||
|
||||
lastSql = upsertQuery.toSQL();
|
||||
await upsertQuery;
|
||||
} else {
|
||||
// No changes, delete from scrapeValidation if it exists
|
||||
const deleteQuery = db
|
||||
.delete(characterScrapeValidation)
|
||||
.where(eq(characterScrapeValidation.id, item.id));
|
||||
|
||||
lastSql = deleteQuery.toSQL();
|
||||
await deleteQuery;
|
||||
}
|
||||
const upsertQuery = db
|
||||
.insert(characterScrapeValidation)
|
||||
.values(jsonData)
|
||||
.onConflictDoUpdate({
|
||||
target: characterScrapeValidation.id,
|
||||
set: jsonData
|
||||
});
|
||||
|
||||
lastSql = upsertQuery.toSQL();
|
||||
await upsertQuery;
|
||||
successCount++;
|
||||
process.stdout.write(`\rProcessed: ${successCount}/${characters.length}`);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user