Restructure duplicate check

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2023-01-12 16:04:37 -08:00
parent 652a76bdd9
commit 8d70f5dc54

View File

@ -311,22 +311,36 @@ const processBlock = async (items) => {
asset.hash = await computeHash( asset.hash = await computeHash(
picturesPath + asset.album.path + asset.filename) picturesPath + asset.album.path + asset.filename)
let results = await photoDB.sequelize.query( /* Writes to DB for new assets hasn't happened yet, so the DB
"SELECT photohashes.*,photos.filename,albums.path FROM photohashes " + * won't have new duplicates */
"LEFT JOIN photos ON (photos.id=photohashes.photoId) " + let duplicate = insertHash.find(entry => entry.hash === asset.hash)
"LEFT JOIN albums ON (albums.id=photos.albumId) " + || updateHash.find(entry => entry.hash === asset.hash);
"WHERE hash=:hash OR photoId=:id", {
replacements: asset,
type: photoDB.sequelize.QueryTypes.SELECT
});
let query;
if (results.length == 0) {
insertHash.push(asset); let results = [];
} else if (results[0].hash != asset.hash) {
updateHash.push(asset); /* In addition to checking new entries, check the DB for old
} else if (results[0].photoId != asset.id) { * duplicates */
if (!duplicate) {
results = await photoDB.sequelize.query(
"SELECT photohashes.*,photos.filename,albums.path FROM photohashes " +
"LEFT JOIN photos ON (photos.id=photohashes.photoId) " +
"LEFT JOIN albums ON (albums.id=photos.albumId) " +
"WHERE hash=:hash OR photoId=:id", {
replacements: asset,
type: photoDB.sequelize.QueryTypes.SELECT
});
if (results.length == 0) {
insertHash.push(asset);
} else if (results[0].hash != asset.hash) {
updateHash.push(asset);
} else if (results[0].photoId != asset.id) {
duplicate = true;
}
}
if (duplicate) {
setStatus("Duplicate asset: " + setStatus("Duplicate asset: " +
"'" + asset.album.path + asset.filename + "' is a copy of " + "'" + asset.album.path + asset.filename + "' is a copy of " +
"'" + results[0].path + results[0].filename + "'"); "'" + results[0].path + results[0].filename + "'");
@ -337,13 +351,6 @@ const processBlock = async (items) => {
return; /* Done processing this asset (DUPLICATE) */ return; /* Done processing this asset (DUPLICATE) */
} }
/* Update PHOTOHASH table if necessary */
if (query) {
await photoDB.sequelize.query(query, {
replacements: asset,
});
}
/* Additional processing is only skipped if the asset was a /* Additional processing is only skipped if the asset was a
* DUPLICATE above (the empty "return;") */ * DUPLICATE above (the empty "return;") */