Cache cleaning/expiry and db saving

master
Kit Kasune 4 years ago
parent 7a31a2e50a
commit b71dc7b24d
  1. 2
      commands/setupleveling.js
  2. 8
      events/ready.js
  3. 19
      util/lxp/cacheloop.js

@ -31,6 +31,8 @@ module.exports = {
rc.on("collect", async r => {
let xp = new LXP({gid: message.guild.id});
xp.msg = r.emoji.name === "👍";
xp.save();
client.misc.cache.lxp.enabled.push(message.guild.id);
return message.channel.send(new Discord.MessageEmbed()
.setTitle("XP System Enabled!")
.setThumbnail(message.guild.iconURL({size: 2048}))

@ -9,8 +9,9 @@ const BotDataSchema = require('../models/bot');
const LogData = require('../models/log');
const siftStatuses = require('../util/siftstatuses');
const localXPCacheClean = require('../util/lxp/cacheloop');
var prefix = 'n?';
let prefix = 'n?';
module.exports = async client => {
const config = client.config;
@ -51,7 +52,6 @@ module.exports = async client => {
else {client.user.setActivity(responses[type][Math.floor(Math.random() * responses[type].length)] + " | " + prefix + "help", {type: type});}
}
setR();
setInterval(setR, 14400000);
const setPL = async () => {let tg; for (tg of Array.from(client.guilds.cache.values)) {
@ -67,12 +67,14 @@ module.exports = async client => {
}
}};
setPL();
siftStatuses();
siftStatuses();
setInterval(() => {setPL(); siftStatuses(client, null);}, 120000);
await require('../util/cache')(client);
setInterval(() => localXPCacheClean(client), 150000);
let botData = await BotDataSchema.findOne({finder: 'lel'})
? await BotDataSchema.findOne({finder: 'lel'})
: new BotDataSchema({

@ -0,0 +1,19 @@
const LXP = require('../../models/localxp');
module.exports = async (client) => {
let cd = new Date().getTime();
await client.misc.cache.lxp.enabled.forEach(gxp => {
LXP.findOne({gid: gxp}).then(xp => {
if (!xp) {return;}
Object.keys(client.misc.cache.lxp.xp[gxp]).forEach(user => {
xp.xp[user] = [client.misc.cache.lxp.xp[gxp][user].xp, client.misc.cache.lxp.xp[gxp][user].level];
xp.markModified(`xp.${user}`);
xp.save();
if (cd - client.misc.cache.lxp.xp[gxp][user].lastXP > 600000) {
delete client.misc.cache.lxp.xp[gxp][user];
if (!Object.keys(client.misc.cache.lxp.xp[gxp]).length) {delete client.misc.cache.lxp.xp[gxp];}
}
});
})
})
};
Loading…
Cancel
Save