This commit is contained in:
Pitu 2021-03-23 22:35:29 +09:00
parent b24c0175f5
commit 541bfedb92
2 changed files with 34 additions and 4 deletions

View File

@ -0,0 +1,10 @@
exports.up = async knex => {
await knex.schema.createTable('settings', table => {
table.string('key').unique();
table.json('value').notNullable();
});
};
exports.down = async knex => {
await knex.schema.dropTableIfExists('settings');
};

View File

@ -15,10 +15,30 @@ const StatsGenerator = require('./StatsGenerator');
const blockedExtensions = process.env.BLOCKED_EXTENSIONS.split(',');
const preserveExtensions = ['.tar.gz', '.tar.z', '.tar.bz2', '.tar.lzma', '.tar.lzo', '.tar.xz'];
let statsLastSavedTime = null;
class Util {
static uploadPath = path.join(__dirname, '../../../', process.env.UPLOAD_FOLDER);
static statsLastSavedTime = null;
static _config = null;
static get config() {
return (async () => {
if (this._config === null) {
const conf = await db('config').select('key', 'value');
this._config = conf.reduce((acc, { key, value }) => {
if (typeof value === 'string' || value instanceof String) {
acc[key] = JSON.parse(value);
} else {
acc[key] = value;
}
}, {});
}
return this._config;
})();
}
static invalidateConfigCache() {
this._config = null;
}
static uuid() {
return uuidv4();
@ -320,7 +340,7 @@ class Util {
// skip generating and saving new stats.
if (!force &&
(!db.userParams.lastMutationTime ||
(statsLastSavedTime && statsLastSavedTime > db.userParams.lastMutationTime)
(Util.statsLastSavedTime && Util.statsLastSavedTime > db.userParams.lastMutationTime)
)
) {
return;
@ -341,7 +361,7 @@ class Util {
await db.table('statistics').insert({ type, data: JSON.stringify(data), createdAt: now, batchId });
}
statsLastSavedTime = now.getTime();
Util.statsLastSavedTime = now.getTime();
} catch (error) {
console.error(error);
}