Added automatic process to delete stale database entries
This commit is contained in:
parent
8d9859ea72
commit
ba07757d1d
3 changed files with 140 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
const gm = require("gm");
|
||||
const cron = require("cron");
|
||||
const { promisify } = require("util");
|
||||
const client = require("../utils/client.js");
|
||||
const database = require("../utils/database.js");
|
||||
|
@ -45,6 +46,19 @@ module.exports = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
const job = new cron.CronJob("0 0 * * 0", async () => {
|
||||
logger.log("Deleting stale guild entries in database...");
|
||||
const guildDB = (await database.guilds.find({}).exec());
|
||||
for (const { id } of guildDB) {
|
||||
if (!client.guilds.get(id)) {
|
||||
await database.guilds.deleteMany({ id: id });
|
||||
logger.log(`Deleted entry for guild ID ${id}.`);
|
||||
}
|
||||
}
|
||||
logger.log("Finished deleting stale entries.");
|
||||
});
|
||||
job.start();
|
||||
|
||||
const global = (await database.global.findOne({}).exec());
|
||||
if (!global) {
|
||||
const countObject = {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue