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:
parent
fa06d76a01
commit
132803eba3
@ -48,7 +48,8 @@ router.get("/*", function(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let source;
|
let source;
|
||||||
switch (req.url) {
|
console.log(JSON.stringify(parts, null, 2));
|
||||||
|
switch (parts.pathname) {
|
||||||
case "/":
|
case "/":
|
||||||
source = "frontend/index.html";
|
source = "frontend/index.html";
|
||||||
break;
|
break;
|
||||||
|
@ -366,8 +366,9 @@ router.get("/status/:token", function(req, res) {
|
|||||||
/**
|
/**
|
||||||
* 1. Look if there are duplicates.
|
* 1. Look if there are duplicates.
|
||||||
* 2. Update all other duplicates to be duplicates of the first image that remains
|
* 2. Update all other duplicates to be duplicates of the first image that remains
|
||||||
* 3. If no duplicates, DELETE the entry from photohashes
|
* 3. If no duplicates, DELETE the entry from referencing tables:
|
||||||
* 4. If there are duplicates, update the HASH entry to point to the first image that remains
|
* 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
|
* 5. Delete the entry from photos
|
||||||
* 6. Delete the scaled, thumb, and original from disk
|
* 6. Delete the scaled, thumb, and original from disk
|
||||||
*/
|
*/
|
||||||
@ -387,7 +388,7 @@ const deletePhoto = function(photo) {
|
|||||||
duplicates.forEach(function(duplicate) {
|
duplicates.forEach(function(duplicate) {
|
||||||
needsUpdate.push(duplicate.id);
|
needsUpdate.push(duplicate.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!needsUpdate.length) {
|
if (!needsUpdate.length) {
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
@ -407,11 +408,19 @@ const deletePhoto = function(photo) {
|
|||||||
}).then(function(first) {
|
}).then(function(first) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
console.log("Deleting "+ photo.id + " from photohash.");
|
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(
|
return photoDB.sequelize.query(
|
||||||
"DELETE FROM photohashes WHERE photoId=:id", {
|
"DELETE FROM photohashes WHERE photoId=:id", {
|
||||||
replacements: photo,
|
replacements: photo,
|
||||||
transaction: transaction
|
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);
|
console.log("Updating photohash for " + photo.id + " to point to " + first.id);
|
||||||
@ -423,6 +432,16 @@ const deletePhoto = function(photo) {
|
|||||||
photo: photo.id
|
photo: photo.id
|
||||||
},
|
},
|
||||||
transaction: transaction
|
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() {
|
}).then(function() {
|
||||||
console.log("Deleting " + photo.path + photo.filename + " from DB.");
|
console.log("Deleting " + photo.path + photo.filename + " from DB.");
|
||||||
|
13
src/App.js
13
src/App.js
@ -582,12 +582,13 @@ function createIdentityBlock(identity, nolimit) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const target = identity.relatedFaces[i];
|
const target = identity.relatedFaces[i];
|
||||||
const facePhoto = createFace(target.faceId, target.photoId),
|
const facePhoto = createFace(target.faceId, target.photoId);
|
||||||
distance = document.createElement("div");
|
if (target.distance > 0.01) {
|
||||||
|
const distance = document.createElement("div");
|
||||||
distance.classList.add("distance");
|
distance.classList.add("distance");
|
||||||
distance.textContent = target.distance.toFixed(2);
|
distance.textContent = target.distance.toFixed(2);
|
||||||
facePhoto.appendChild(distance);
|
facePhoto.appendChild(distance);
|
||||||
|
}
|
||||||
div.appendChild(facePhoto);
|
div.appendChild(facePhoto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user