mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 00:03:09 +02:00
perf(sqlite): run optimize
every 6h
This commit is contained in:
parent
318b969f39
commit
8971c0ad13
@ -11,6 +11,7 @@ const { join } = require('path');
|
|||||||
const YAML = require('yaml');
|
const YAML = require('yaml');
|
||||||
const TicketManager = require('./lib/tickets/manager');
|
const TicketManager = require('./lib/tickets/manager');
|
||||||
const sqliteMiddleware = require('./lib/middleware/prisma-sqlite');
|
const sqliteMiddleware = require('./lib/middleware/prisma-sqlite');
|
||||||
|
const ms = require('ms');
|
||||||
|
|
||||||
module.exports = class Client extends FrameworkClient {
|
module.exports = class Client extends FrameworkClient {
|
||||||
constructor(config, log) {
|
constructor(config, log) {
|
||||||
@ -53,13 +54,19 @@ module.exports = class Client extends FrameworkClient {
|
|||||||
async login(token) {
|
async login(token) {
|
||||||
/** @type {PrismaClient} */
|
/** @type {PrismaClient} */
|
||||||
this.prisma = new PrismaClient();
|
this.prisma = new PrismaClient();
|
||||||
|
|
||||||
if (process.env.DB_PROVIDER === 'sqlite') {
|
if (process.env.DB_PROVIDER === 'sqlite') {
|
||||||
|
// rewrite queries that use unsupported features
|
||||||
this.prisma.$use(sqliteMiddleware);
|
this.prisma.$use(sqliteMiddleware);
|
||||||
// make sqlite faster,
|
// make sqlite faster (missing parentheses are not a mistake, `$queryRaw` is a tagged template literal)
|
||||||
// and the missing parentheses are not a mistake, `$queryRaw` is a tagged template literal
|
|
||||||
this.log.debug(await this.prisma.$queryRaw`PRAGMA journal_mode=WAL;`); // https://www.sqlite.org/wal.html
|
this.log.debug(await this.prisma.$queryRaw`PRAGMA journal_mode=WAL;`); // https://www.sqlite.org/wal.html
|
||||||
this.log.debug(await this.prisma.$queryRaw`PRAGMA synchronous=normal;`); // https://www.sqlite.org/pragma.html#pragma_synchronous
|
this.log.debug(await this.prisma.$queryRaw`PRAGMA synchronous=normal;`); // https://www.sqlite.org/pragma.html#pragma_synchronous
|
||||||
|
|
||||||
|
setInterval(async () => {
|
||||||
|
this.log.debug(await this.prisma.$queryRaw`PRAGMA optimize;`); // https://www.sqlite.org/pragma.html#pragma_optimize
|
||||||
|
}, ms('6h'));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.keyv = new Keyv();
|
this.keyv = new Keyv();
|
||||||
return super.login(token);
|
return super.login(token);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user