Update core client to support mongodb in addition to nedb
This commit is contained in:
parent
559a61828d
commit
f7c00f898c
|
@ -7,7 +7,7 @@ const HandleGuildMessage = require("./handle-guild-message.js");
|
||||||
const InternalConfig = require("./internal-config.json");
|
const InternalConfig = require("./internal-config.json");
|
||||||
const RequireAll = require("require-all");
|
const RequireAll = require("require-all");
|
||||||
|
|
||||||
let neDB;
|
let database;
|
||||||
|
|
||||||
module.exports = class Client extends Discord.Client {
|
module.exports = class Client extends Discord.Client {
|
||||||
/**
|
/**
|
||||||
|
@ -74,9 +74,16 @@ module.exports = class Client extends Discord.Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
bootstrap() {
|
bootstrap() {
|
||||||
Camo.connect("nedb://guilds-data").then(db => {
|
Camo.connect(InternalConfig.dbConnectionString).then(db => {
|
||||||
neDB = db;
|
database = db;
|
||||||
new CronJob(InternalConfig.dbCompactionSchedule, compactCollections, null, true);
|
|
||||||
|
const dbProtocol = InternalConfig.dbConnectionString.match(/^(.+):\/\//)[1];
|
||||||
|
CoreUtil.dateLog(`Database protocol: ${dbProtocol}`);
|
||||||
|
|
||||||
|
if (dbProtocol === "nedb") {
|
||||||
|
CoreUtil.dateLog(`Seting up NeDB collection compaction cron job; schedule: ${InternalConfig.neDBCompactionSchedule}`);
|
||||||
|
new CronJob(InternalConfig.neDBCompactionSchedule, compactNeDBCollections, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
this.emit("beforeLogin");
|
this.emit("beforeLogin");
|
||||||
this.login(this._token);
|
this.login(this._token);
|
||||||
|
@ -92,11 +99,11 @@ module.exports = class Client extends Discord.Client {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function compactCollections() {
|
function compactNeDBCollections() {
|
||||||
/*I realise it is a bit of a cheat to just access _collections in this manner, but in the absence of
|
/*I realise it is a bit of a cheat to just access _collections in this manner, but in the absence of
|
||||||
camo actually having any kind of solution for this it's the easiest method I could come up with.
|
camo actually having any kind of solution for this it's the easiest method I could come up with.
|
||||||
Maybe at some point in future I should fork camo and add this feature. The compaction function is NeDB only
|
Maybe at some point in future I should fork camo and add this feature. The compaction function is NeDB only
|
||||||
and camo is designed to work with both NeDB and MongoDB, which is presumably why it doesn't alraedy exist */
|
and camo is designed to work with both NeDB and MongoDB, which is presumably why it doesn't alraedy exist */
|
||||||
for (let collectionName of Object.keys(neDB._collections))
|
for (let collectionName of Object.keys(database._collections))
|
||||||
neDB._collections[collectionName].persistence.compactDatafile();
|
database._collections[collectionName].persistence.compactDatafile();
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"dbCompactionSchedule": "0 * * * * *",
|
"dbConnectionString": "nedb://guilds-data",
|
||||||
|
"neDBCompactionSchedule": "0 * * * * *",
|
||||||
"restartSchedule": "0 0 0 * * *",
|
"restartSchedule": "0 0 0 * * *",
|
||||||
"restartTimeout": 5000,
|
"restartTimeout": 5000,
|
||||||
"website": "https://benji7425.github.io",
|
"website": "https://benji7425.github.io",
|
||||||
|
|
Loading…
Reference in a new issue