1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/packages/lib/migrations/20.js

30 lines
848 B
JavaScript
Raw Normal View History

2020-11-05 18:58:23 +02:00
const Resource = require('../models/Resource');
const Setting = require('../models/Setting').default;
const shim = require('../shim').default;
const { reg } = require('../registry.js');
const { fileExtension } = require('../path-utils');
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 = [];
for (const stat of stats) {
2019-07-29 15:43:53 +02:00
if (fileExtension(stat.path) === 'crypted') continue;
const resourceId = Resource.pathToId(stat.path);
if (!resourceId) continue;
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);
2019-07-29 15:43:53 +02:00
};
2019-07-29 15:43:53 +02:00
module.exports = script;