Restructured and removed transaction usage during update due to DB lockups
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
2d9aa1a9f6
commit
3e6bb96ab8
@ -551,7 +551,7 @@ const findOrCreateDBAlbum = async (t, album) => {
|
|||||||
return album.id;
|
return album.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const findOrUpdateDBAsset = async (t, asset) => {
|
const findOrUpdateDBAsset = async (asset) => {
|
||||||
if (!asset.album || !asset.album.id) {
|
if (!asset.album || !asset.album.id) {
|
||||||
let error = "Asset being processed without an album";
|
let error = "Asset being processed without an album";
|
||||||
setStatus(error, "warn");
|
setStatus(error, "warn");
|
||||||
@ -569,10 +569,10 @@ const findOrUpdateDBAsset = async (t, asset) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (results.length == 0) {
|
if (results.length == 0) {
|
||||||
return await photoDB.sequelize.query("INSERT INTO photos " +
|
return photoDB.sequelize.query(
|
||||||
|
"INSERT INTO photos " +
|
||||||
"(albumId,filename,name,size) VALUES(:albumId,:filename,:name,:size)", {
|
"(albumId,filename,name,size) VALUES(:albumId,:filename,:name,:size)", {
|
||||||
replacements: asset,
|
replacements: asset
|
||||||
transaction: t
|
|
||||||
}).then(array => {
|
}).then(array => {
|
||||||
asset.id = array[1].lastID;
|
asset.id = array[1].lastID;
|
||||||
return asset;
|
return asset;
|
||||||
@ -583,8 +583,9 @@ const findOrUpdateDBAsset = async (t, asset) => {
|
|||||||
asset.scanned = new Date(results[0].scanned);
|
asset.scanned = new Date(results[0].scanned);
|
||||||
asset.modified = new Date(results[0].modified);
|
asset.modified = new Date(results[0].modified);
|
||||||
|
|
||||||
/* If the size on disk changed, update the size entry in the DB. This shouldn't happen in
|
/* If the size on disk changed, update the size entry in the DB. This
|
||||||
* production unless someone modifies the file, then re-stamps the modified time */
|
* shouldn't happen in production unless someone modifies the file, then
|
||||||
|
* re-stamps the modified time */
|
||||||
if (asset.size != results[0].size) {
|
if (asset.size != results[0].size) {
|
||||||
setStatus("File was modified with time-restamp (HASH regeneration will be queued): " + asset.filename);
|
setStatus("File was modified with time-restamp (HASH regeneration will be queued): " + asset.filename);
|
||||||
delete asset.scanned;
|
delete asset.scanned;
|
||||||
@ -722,8 +723,7 @@ const doScan = async () => {
|
|||||||
start = Date.now(),
|
start = Date.now(),
|
||||||
last = 0;
|
last = 0;
|
||||||
|
|
||||||
await photoDB.sequelize.transaction(async (t) => {
|
await Promise.mapSeries(assets, async (asset) => {
|
||||||
await Promise.map(assets, async (asset) => {
|
|
||||||
/* If both mtime and ctime of the asset are older than the
|
/* If both mtime and ctime of the asset are older than the
|
||||||
* lastScan, skip it
|
* lastScan, skip it
|
||||||
* Can only do this after a full scan has occurred */
|
* Can only do this after a full scan has occurred */
|
||||||
@ -733,7 +733,7 @@ const doScan = async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
asset = await findOrUpdateDBAsset(t, asset);
|
asset = await findOrUpdateDBAsset(asset);
|
||||||
if (!asset.scanned) {
|
if (!asset.scanned) {
|
||||||
newEntries++;
|
newEntries++;
|
||||||
}
|
}
|
||||||
@ -759,16 +759,15 @@ const doScan = async () => {
|
|||||||
let remaining = assets.length - processed,
|
let remaining = assets.length - processed,
|
||||||
eta = Math.ceil((elapsed / 1000) * remaining / (processed - last));
|
eta = Math.ceil((elapsed / 1000) * remaining / (processed - last));
|
||||||
setStatus(
|
setStatus(
|
||||||
`${remaining} assets remaining be verified/updated (${newEntries} ` +
|
`${remaining} assets remaining to be verified/updated (${newEntries} ` +
|
||||||
`new entries, ${needsProcessing.length} need processing, ` +
|
`new entries, ${needsProcessing.length} need processing, ` +
|
||||||
`${(processed - newEntries)} up-to-date so far). ETA ${eta}s`
|
`${(processed - newEntries)} up-to-date so far). ETA ${eta}s`
|
||||||
);
|
);
|
||||||
last = processed;
|
last = processed;
|
||||||
start = Date.now();
|
start = Date.now();
|
||||||
}, {
|
/*, {
|
||||||
concurrency: 10
|
concurrency: 10
|
||||||
});
|
*/});
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user