2019-05-11 18:55:40 +02:00
|
|
|
const Resource = require('lib/models/Resource');
|
|
|
|
const Setting = require('lib/models/Setting');
|
|
|
|
const { shim } = require('lib/shim');
|
|
|
|
const { reg } = require('lib/registry.js');
|
2019-05-12 12:41:07 +02:00
|
|
|
const { fileExtension } = require('lib/path-utils.js');
|
2019-05-11 18:55:40 +02:00
|
|
|
|
|
|
|
const script = {};
|
|
|
|
|
|
|
|
script.exec = async function() {
|
|
|
|
const stats = await shim.fsDriver().readDirStats(Setting.value('resourceDir'));
|
|
|
|
|
2019-05-13 10:50:39 +02:00
|
|
|
let queries = [];
|
2019-05-11 18:55:40 +02:00
|
|
|
for (const stat of stats) {
|
2019-05-12 12:41:07 +02:00
|
|
|
if (fileExtension(stat.path) === 'crypted') continue;
|
2019-05-11 18:55:40 +02:00
|
|
|
const resourceId = Resource.pathToId(stat.path);
|
2019-05-12 12:41:07 +02:00
|
|
|
if (!resourceId) continue;
|
|
|
|
|
2019-05-11 18:55:40 +02:00
|
|
|
queries.push({ sql: 'UPDATE resources SET `size` = ? WHERE id = ?', params: [stat.size, resourceId] });
|
|
|
|
|
|
|
|
if (queries.length >= 1000) {
|
|
|
|
await reg.db().transactionExecBatch(queries);
|
|
|
|
queries = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await reg.db().transactionExecBatch(queries);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = script;
|