Update to delete faces prior to deleting photo to resolve foreignkey constraints

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2021-02-01 12:31:59 -08:00
parent fa06d76a01
commit 132803eba3
3 changed files with 32 additions and 11 deletions

View File

@ -48,7 +48,8 @@ router.get("/*", function(req, res, next) {
}
let source;
switch (req.url) {
console.log(JSON.stringify(parts, null, 2));
switch (parts.pathname) {
case "/":
source = "frontend/index.html";
break;

View File

@ -366,8 +366,9 @@ router.get("/status/:token", function(req, res) {
/**
* 1. Look if there are duplicates.
* 2. Update all other duplicates to be duplicates of the first image that remains
* 3. If no duplicates, DELETE the entry from photohashes
* 4. If there are duplicates, update the HASH entry to point to the first image that remains
* 3. If no duplicates, DELETE the entry from referencing tables:
* photohashes, faces
* 4. If there are duplicates, update the HASH (and any FACE) entry to point to the first image that remains
* 5. Delete the entry from photos
* 6. Delete the scaled, thumb, and original from disk
*/
@ -407,11 +408,19 @@ const deletePhoto = function(photo) {
}).then(function(first) {
if (!first) {
console.log("Deleting "+ photo.id + " from photohash.");
// 3. If no duplicates, DELETE the entry from photohashes
// 3. If no duplicates, DELETE the entry from photohashes and faces
return photoDB.sequelize.query(
"DELETE FROM photohashes WHERE photoId=:id", {
replacements: photo,
transaction: transaction
}).then(() => {
console.log("Deleting "+ photo.id + " from faces.");
// 3. If no duplicates, DELETE the entry from photohashes
return photoDB.sequelize.query(
"DELETE FROM faces WHERE photoId=:id", {
replacements: photo,
transaction: transaction
});
});
}
console.log("Updating photohash for " + photo.id + " to point to " + first.id);
@ -423,6 +432,16 @@ const deletePhoto = function(photo) {
photo: photo.id
},
transaction: transaction
}).then(() => {
console.log("Updating faces for " + photo.id + " to point to " + first.id);
return photoDB.sequelize.query(
"UPDATE faces SET photoId=:first WHERE photoId=:photo", {
replacements: {
first: first.id,
photo: photo.id
},
transaction: transaction
});
});
}).then(function() {
console.log("Deleting " + photo.path + photo.filename + " from DB.");

View File

@ -582,12 +582,13 @@ function createIdentityBlock(identity, nolimit) {
break;
}
const target = identity.relatedFaces[i];
const facePhoto = createFace(target.faceId, target.photoId),
distance = document.createElement("div");
const facePhoto = createFace(target.faceId, target.photoId);
if (target.distance > 0.01) {
const distance = document.createElement("div");
distance.classList.add("distance");
distance.textContent = target.distance.toFixed(2);
facePhoto.appendChild(distance);
}
div.appendChild(facePhoto);
}