Partial size tracking
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
cb8437a55b
commit
a391848ec9
@ -575,31 +575,42 @@ function findOrCreateDBAlbum(transaction, album) {
|
||||
}
|
||||
|
||||
function findOrUpdateDBAsset(transaction, asset) {
|
||||
let query = "SELECT id,DATETIME(scanned) AS scanned,DATETIME(modified) AS modified FROM photos " +
|
||||
"WHERE albumId=:albumId AND filename=:filename";
|
||||
if (!asset.album || !asset.album.id) {
|
||||
let error = "Asset being processed without an album";
|
||||
console.error(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
asset.albumId = asset.album.id;
|
||||
return photoDB.sequelize.query(query, {
|
||||
|
||||
return photoDB.sequelize.query(
|
||||
"SELECT id,DATETIME(scanned) AS scanned,size,DATETIME(modified) AS modified " +
|
||||
"FROM photos " +
|
||||
"WHERE albumId=:albumId AND filename=:filename", {
|
||||
replacements: asset,
|
||||
type: photoDB.sequelize.QueryTypes.SELECT
|
||||
}).then(function(results) {
|
||||
if (results.length == 0) {
|
||||
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,
|
||||
transaction: transaction
|
||||
}).spread(function(results, metadata) {
|
||||
asset.id = metadata.lastID;
|
||||
});
|
||||
} else {
|
||||
asset.id = results[0].id;
|
||||
asset.scanned = new Date(results[0].scanned);
|
||||
asset.modified = new Date(results[0].modified);
|
||||
}
|
||||
|
||||
asset.id = results[0].id;
|
||||
asset.scanned = new Date(results[0].scanned);
|
||||
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
|
||||
* production unless someone modifies the file, then re-stamps the modified time */
|
||||
if (asset.size != results[0].size) {
|
||||
return photoDB.sequelize.query("UPDATE photos SET size=:size WHERE id=:id", {
|
||||
replacements: asset,
|
||||
transaction: transaction
|
||||
});
|
||||
}
|
||||
}).then(function() {
|
||||
return asset;
|
||||
@ -681,11 +692,12 @@ function doScan() {
|
||||
let processed = 0, start = Date.now(), last = 0, updateScanned = [], newEntries = 0;
|
||||
return photoDB.sequelize.transaction(function(transaction) {
|
||||
return Promise.map(assets, function(asset) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
return Promise.resolve(asset).then(function(asset) {
|
||||
/* If both mtime and ctime of the asset are older than the lastScan, skip it
|
||||
* Can only do this after a full scan has occurred */
|
||||
*
|
||||
* Can only do this after a full scan has occurred */
|
||||
if (lastScan != null && asset.stats.mtime < lastScan && asset.stats.ctime < lastScan) {
|
||||
return resolve(asset);
|
||||
return asset;
|
||||
}
|
||||
|
||||
return findOrUpdateDBAsset(transaction, asset).then(function(asset) {
|
||||
@ -699,9 +711,7 @@ function doScan() {
|
||||
}
|
||||
return asset;
|
||||
}).then(function(asset) {
|
||||
return resolve(asset);
|
||||
}).catch(function(error) {
|
||||
return reject(error);
|
||||
return asset;
|
||||
});
|
||||
}).then(function(asset) {
|
||||
processed++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user