diff --git a/migrations/20260125052234_fingerprints.js b/migrations/20260125052234_fingerprints.js index 24285094..21cfefe3 100644 --- a/migrations/20260125052234_fingerprints.js +++ b/migrations/20260125052234_fingerprints.js @@ -42,6 +42,11 @@ exports.up = async (knex) => { table.integer('source_submissions'); table.json('source_meta'); + table.integer('batch_id') + .notNullable() + .references('id') + .inTable('batches'); + table.datetime('source_created_at'); table.datetime('created_at') diff --git a/src/tools/stashdb-hashes.js b/src/tools/stashdb-hashes.js index 35489ffa..4c3d1a1f 100644 --- a/src/tools/stashdb-hashes.js +++ b/src/tools/stashdb-hashes.js @@ -1,6 +1,6 @@ 'use strict'; -const util = require('util'); +// const util = require('util'); const unprint = require('unprint'); const args = require('yargs').argv; @@ -79,7 +79,10 @@ async function curateData(data) { return release; }); + console.log(`Found ${stashScenes.length} scenes in StashDB`); + const stashScenesByIdentifiers = Object.fromEntries(stashScenes.flatMap((scene) => [[scene.entryId || scene.urlId, scene], [scene.url, scene]])); + const [{ id: batchId }] = await knex('batches').insert({ showcased: false, comment: 'StashDB fingerprints' }).returning('id'); const sceneEntries = await knex('releases') .select('releases.*') @@ -88,6 +91,8 @@ async function curateData(data) { .where('entities.slug', 'hardx') .whereIn('entry_id', stashScenes.map((scene) => scene.entryId || scene.urlId)); + console.log(`Matched ${sceneEntries.length} scenes`); + const fpEntries = sceneEntries.flatMap((scene) => { const stashScene = stashScenesByIdentifiers[scene.entry_id] || stashScenesByIdentifiers[scene.url]; @@ -108,15 +113,16 @@ async function curateData(data) { url: stashScene.url, date: stashScene.date, }, + batch_id: batchId, })); }); - console.log(util.inspect(fpEntries, { colors: true, depth: null, maxArrayLength: null })); + // console.log(util.inspect(fpEntries, { colors: true, depth: null, maxArrayLength: null })); if (args.update) { await bulkInsert('releases_fingerprints', fpEntries, false); - console.log(`Inserted ${fpEntries.length} hash entries`); + console.log(`Inserted ${fpEntries.length} hash entries in batch ${batchId}`); } }