Moved toke log to it's own DB collection w/ cached statistics. Tokebot statistics page-load time decreased by up to 20-30x

This commit is contained in:
rainbow napkin 2025-10-12 23:48:45 -04:00
parent 42ad17072f
commit a1b602efdb
7 changed files with 281 additions and 189 deletions

View file

@ -42,6 +42,7 @@ const {errorMiddleware} = require('./utils/loggerUtils');
const statModel = require('./schemas/statSchema');
const flairModel = require('./schemas/flairSchema');
const emoteModel = require('./schemas/emoteSchema');
const tokeModel = require('./schemas/tokebot/tokeSchema');
const tokeCommandModel = require('./schemas/tokebot/tokeCommandSchema');
const migrationModel = require('./schemas/user/migrationSchema');
//Controller
@ -181,29 +182,43 @@ app.use(errorMiddleware);
//Basic 404 handler
app.use(fileNotFoundController);
//Increment launch counter
statModel.incrementLaunchCount();
asyncKickStart();
//Load default flairs
flairModel.loadDefaults();
/*Asyncronous Kickstarter function
Allows us to force server startup to wait on the DB to be ready.
Might be better if she kicked off everything at once, and ran a while loop to check when they where all done.
This runs once at server startup, and most startups will run fairly quickly so... Not worth it?*/
async function asyncKickStart(){
//Lettum fuckin' know wassup
console.log(`${config.instanceName}(Powered by Canopy) is booting up!`);
//Load default emotes
emoteModel.loadDefaults();
//Run legacy migration
await migrationModel.ingestLegacyDump();
//Load default toke commands
tokeCommandModel.loadDefaults();
//Calculate Toke Map
await tokeModel.calculateTokeMap();
//Run legacy migration
migrationModel.ingestLegacyDump();
//Load default toke commands
await tokeCommandModel.loadDefaults();
//Kick off scheduled-jobs
scheduler.kickoff();
//Load default flairs
await flairModel.loadDefaults();
//Hand over general-namespace socket.io connections to the channel manager
module.exports.channelManager = new channelManager(io)
module.exports.pmHandler = new pmHandler(io, module.exports.channelManager);
//Load default emotes
await emoteModel.loadDefaults();
//Listen Function
webServer.listen(port, () => {
console.log(`Opening port ${port}`);
});
//Kick off scheduled-jobs
scheduler.kickoff();
//Increment launch counter
await statModel.incrementLaunchCount();
//Hand over general-namespace socket.io connections to the channel manager
module.exports.channelManager = new channelManager(io)
module.exports.pmHandler = new pmHandler(io, module.exports.channelManager);
//Listen Function
webServer.listen(port, () => {
console.log(`Tokes up on port ${port}!`);
});
}