Do not scan duplicates or deleted images

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2020-01-05 10:10:30 -08:00
parent 6c5de402db
commit 756272ea6a
3 changed files with 26 additions and 12 deletions

View File

@ -294,7 +294,12 @@ document.addEventListener("DOMContentLoaded", function() {
} }
window.fetch("api/v1/photos/random" + id) window.fetch("api/v1/photos/random" + id)
.then(res => res.json()).then(function(data) { .then((res) => {
if (res.status >= 400) {
throw res.status;
}
return res.json();
}).then(function(data) {
info.textContent = "Random photo: " + data.id; info.textContent = "Random photo: " + data.id;
photoIndex = 0; photoIndex = 0;
photos = [data]; photos = [data];

View File

@ -61,7 +61,7 @@ faceapi.nets.ssdMobilenetv1.loadFromDisk('./models')
return photoDB.sequelize.query("SELECT photos.id,photos.filename,photos.width,photos.height,albums.path " + return photoDB.sequelize.query("SELECT photos.id,photos.filename,photos.width,photos.height,albums.path " +
"FROM photos " + "FROM photos " +
"LEFT JOIN albums ON (albums.id=photos.albumId) " + "LEFT JOIN albums ON (albums.id=photos.albumId) " +
"WHERE faces=-1 AND deleted=0 ORDER BY albums.path,photos.filename", { "WHERE faces=-1 AND photos.duplicate=0 AND photos.deleted=0 ORDER BY albums.path,photos.filename", {
type: photoDB.sequelize.QueryTypes.SELECT, type: photoDB.sequelize.QueryTypes.SELECT,
raw: true raw: true
} }
@ -166,7 +166,7 @@ faceapi.nets.ssdMobilenetv1.loadFromDisk('./models')
console.log("Looking for face distances that need to be updated..."); console.log("Looking for face distances that need to be updated...");
const descriptors = {}; const descriptors = {};
return photoDB.sequelize.query("SELECT id FROM faces ORDER BY id DESC LIMIT 1", { return photoDB.sequelize.query("SELECT faces.id FROM faces ORDER BY faces.id DESC LIMIT 1", {
type: photoDB.sequelize.QueryTypes.SELECT, type: photoDB.sequelize.QueryTypes.SELECT,
raw: true raw: true
}).then((results) => { }).then((results) => {
@ -176,9 +176,9 @@ faceapi.nets.ssdMobilenetv1.loadFromDisk('./models')
} }
const maxId = results[0].id; const maxId = results[0].id;
return photoDB.sequelize.query( return photoDB.sequelize.query(
"SELECT id,lastComparedId " + "SELECT faces.id,faces.lastComparedId " +
"FROM faces " + "FROM faces INNER JOIN photos ON photos.duplicate=0 AND photos.deleted=0 AND photos.id=faces.photoId " +
"WHERE lastComparedId<:maxId OR lastComparedId IS NULL", { "WHERE faces.lastComparedId<:maxId OR faces.lastComparedId IS NULL", {
replacements: { replacements: {
maxId: maxId maxId: maxId
}, },

View File

@ -836,15 +836,18 @@ router.get("/faces/:id", (req, res) => {
}); });
router.get("/random/:id?", (req, res) => { router.get("/random/:id?", (req, res) => {
const id = parseInt(req.params.id); let id = parseInt(req.params.id),
let filter = ""; filter = "";
if (id == req.params.id) { if (id == req.params.id) {
console.log("GET /random/" + id);
filter = "AND id=:id"; filter = "AND id=:id";
} else { } else {
filter = "AND faces>0"; filter = "AND faces>0";
id = undefined;
} }
return photoDB.sequelize.query("SELECT id FROM photos WHERE deleted=0 " + filter, {
return photoDB.sequelize.query("SELECT id,duplicate FROM photos WHERE deleted=0 " + filter, {
replacements: { replacements: {
id: id id: id
}, },
@ -852,9 +855,15 @@ router.get("/random/:id?", (req, res) => {
raw: true raw: true
}).then((results) => { }).then((results) => {
if (!results.length) { if (!results.length) {
return res.status(404); return res.status(404).send(id + " not found.");
}
if (id) {
if (results[0].duplicate) {
id = results[0].duplicate;
}
} else {
id = results[Math.floor(Math.random() * results.length)].id;
} }
const id = results[Math.floor(Math.random() * results.length)].id;
return photoDB.sequelize.query( return photoDB.sequelize.query(
"SELECT photos.*,albums.path AS path FROM photos " + "SELECT photos.*,albums.path AS path FROM photos " +
@ -868,7 +877,7 @@ router.get("/random/:id?", (req, res) => {
}); });
}).then(function(photos) { }).then(function(photos) {
if (!photos.length) { if (!photos.length) {
return res.status(404); return res.status(404).send(id + " not found.");
} }
const photo = photos[0]; const photo = photos[0];
for (var key in photo) { for (var key in photo) {