mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-12 08:54:00 +02:00
25 lines
702 B
JavaScript
25 lines
702 B
JavaScript
|
const Resource = require('lib/models/Resource');
|
||
|
const Setting = require('lib/models/Setting');
|
||
|
const { shim } = require('lib/shim');
|
||
|
const { reg } = require('lib/registry.js');
|
||
|
|
||
|
const script = {};
|
||
|
|
||
|
script.exec = async function() {
|
||
|
const stats = await shim.fsDriver().readDirStats(Setting.value('resourceDir'));
|
||
|
|
||
|
const queries = [];
|
||
|
for (const stat of stats) {
|
||
|
const resourceId = Resource.pathToId(stat.path);
|
||
|
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;
|