Improvements to network connections on startup
This commit is contained in:
parent
d8a6b137fe
commit
a0c2495c42
@ -61,7 +61,6 @@ function Client(manager, name, config = {}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const client = this;
|
const client = this;
|
||||||
let delay = 0;
|
|
||||||
|
|
||||||
if (!Helper.config.public && client.config.log) {
|
if (!Helper.config.public && client.config.log) {
|
||||||
if (Helper.config.messageStorage.includes("sqlite")) {
|
if (Helper.config.messageStorage.includes("sqlite")) {
|
||||||
@ -77,12 +76,11 @@ function Client(manager, name, config = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(client.config.networks || []).forEach((n) => {
|
(client.config.networks || []).forEach((network) => client.connect(network, true));
|
||||||
setTimeout(function() {
|
|
||||||
client.connect(n);
|
// Networks are stored directly in the client object
|
||||||
}, delay);
|
// We don't need to keep it in the config object
|
||||||
delay += 1000;
|
delete client.config.networks;
|
||||||
});
|
|
||||||
|
|
||||||
if (typeof client.config.sessions !== "object") {
|
if (typeof client.config.sessions !== "object") {
|
||||||
client.config.sessions = {};
|
client.config.sessions = {};
|
||||||
@ -106,6 +104,21 @@ function Client(manager, name, config = {}) {
|
|||||||
|
|
||||||
if (client.name) {
|
if (client.name) {
|
||||||
log.info(`User ${colors.bold(client.name)} loaded`);
|
log.info(`User ${colors.bold(client.name)} loaded`);
|
||||||
|
|
||||||
|
// Networks are created instantly, but to reduce server load on startup
|
||||||
|
// We randomize the IRC connections and channel log loading
|
||||||
|
let delay = manager.clients.length * 500;
|
||||||
|
client.networks.forEach((network) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
network.channels.forEach((channel) => channel.loadMessages(client, network));
|
||||||
|
|
||||||
|
if (!network.userDisconnected && network.irc) {
|
||||||
|
network.irc.connect();
|
||||||
|
}
|
||||||
|
}, delay);
|
||||||
|
|
||||||
|
delay += 1000 + Math.floor(Math.random() * 1000);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +156,7 @@ Client.prototype.find = function(channelId) {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.connect = function(args) {
|
Client.prototype.connect = function(args, isStartup = false) {
|
||||||
const client = this;
|
const client = this;
|
||||||
let channels = [];
|
let channels = [];
|
||||||
|
|
||||||
@ -240,13 +253,14 @@ Client.prototype.connect = function(args) {
|
|||||||
}),
|
}),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
} else {
|
} else if (!isStartup) {
|
||||||
network.irc.connect();
|
network.irc.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isStartup) {
|
||||||
client.save();
|
client.save();
|
||||||
|
|
||||||
channels.forEach((channel) => channel.loadMessages(client, network));
|
channels.forEach((channel) => channel.loadMessages(client, network));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.generateToken = function(callback) {
|
Client.prototype.generateToken = function(callback) {
|
||||||
|
@ -10,9 +10,15 @@ describe("Custom highlights", function() {
|
|||||||
let userLoadedLog = "";
|
let userLoadedLog = "";
|
||||||
stub(log, "info").callsFake(TestUtil.sanitizeLog((str) => (userLoadedLog += str)));
|
stub(log, "info").callsFake(TestUtil.sanitizeLog((str) => (userLoadedLog += str)));
|
||||||
|
|
||||||
const client = new Client({}, "test", {
|
const client = new Client(
|
||||||
|
{
|
||||||
|
clients: [],
|
||||||
|
},
|
||||||
|
"test",
|
||||||
|
{
|
||||||
clientSettings: {highlights: "foo, @all, sp ace , 고"},
|
clientSettings: {highlights: "foo, @all, sp ace , 고"},
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
log.info.restore();
|
log.info.restore();
|
||||||
expect(userLoadedLog).to.equal("User test loaded\n");
|
expect(userLoadedLog).to.equal("User test loaded\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user