Add --quick option to fb scan ...

This commit is contained in:
Bryan Ashby 2018-02-16 23:00:15 -07:00
parent cd51cc1adb
commit 9ad38f84a7
2 changed files with 134 additions and 23 deletions

View File

@ -221,6 +221,19 @@ module.exports = class FileEntry {
return paths.join(storageDir, this.fileName);
}
static quickCheckExistsByPath(fullPath, cb) {
fileDb.get(
`SELECT COUNT() AS count
FROM file
WHERE file_name = ?
LIMIT 1;`,
[ paths.basename(fullPath) ],
(err, rows) => {
return err ? cb(err) : cb(null, rows.count > 0 ? true : false);
}
);
}
static persistUserRating(fileId, userId, rating, cb) {
return fileDb.run(
`REPLACE INTO file_user_rating (file_id, user_id, rating)

View File

@ -117,6 +117,8 @@ function scanFileAreaForChanges(areaInfo, options, cb) {
}
}
const FileEntry = require('../file_entry.js');
async.eachSeries(storageLocations, (storageLoc, nextLocation) => {
async.waterfall(
[
@ -157,6 +159,23 @@ function scanFileAreaForChanges(areaInfo, options, cb) {
process.stdout.write(`Scanning ${fullPath}... `);
async.series(
[
function quickCheck(next) {
if(!options.quick) {
return next(null);
}
FileEntry.quickCheckExistsByPath(fullPath, (err, exists) => {
if(exists) {
console.info('Dupe');
return nextFile(null);
}
return next(null);
});
},
function fullScan() {
fileArea.scanFile(
fullPath,
{
@ -229,6 +248,84 @@ function scanFileAreaForChanges(areaInfo, options, cb) {
});
}
);
}
]
);
/*
fileArea.scanFile(
fullPath,
{
areaTag : areaInfo.areaTag,
storageTag : storageLoc.storageTag
},
(err, fileEntry, dupeEntries) => {
if(err) {
console.info(`Error: ${err.message}`);
return nextFile(null); // try next anyway
}
//
// We'll update the entry if the following conditions are met:
// * We have a single duplicate, and:
// * --update was passed or the existing entry's desc,
// longDesc, or est_release_year meta are blank/empty
//
if(argv.update && 1 === dupeEntries.length) {
const FileEntry = require('../../core/file_entry.js');
const existingEntry = new FileEntry();
return existingEntry.load(dupeEntries[0].fileId, err => {
if(err) {
console.info('Dupe (cannot update)');
return nextFile(null);
}
//
// Update only if tags or desc changed
//
const optTags = Array.isArray(options.tags) ? new Set(options.tags) : existingEntry.hashTags;
const tagsEq = _.isEqual(optTags, existingEntry.hashTags);
if( tagsEq &&
fileEntry.desc === existingEntry.desc &&
fileEntry.descLong == existingEntry.descLong &&
fileEntry.meta.est_release_year == existingEntry.meta.est_release_year)
{
console.info('Dupe');
return nextFile(null);
}
console.info('Dupe (updating)');
// don't allow overwrite of values if new version is blank
existingEntry.desc = fileEntry.desc || existingEntry.desc;
existingEntry.descLong = fileEntry.descLong || existingEntry.descLong;
if(fileEntry.meta.est_release_year) {
existingEntry.meta.est_release_year = fileEntry.meta.est_release_year;
}
updateTags(existingEntry);
finalizeEntryAndPersist(true, existingEntry, descHandler, err => {
return nextFile(err);
});
});
} else if(dupeEntries.length > 0) {
console.info('Dupe');
return nextFile(null);
}
console.info('Done!');
updateTags(fileEntry);
finalizeEntryAndPersist(false, fileEntry, descHandler, err => {
return nextFile(err);
});
}
);
*/
});
}, err => {
return callback(err);
@ -397,6 +494,7 @@ function scanFileAreas() {
}
options.descFile = argv['desc-file']; // --desc-file or --desc-file PATH
options.quick = argv.quick;
options.areaAndStorageInfo = getAreaAndStorage(argv._.slice(2));