mirror of https://github.com/calzoneman/sync.git
Warn moderators when a channel exceeds size limit
When the chandump is saved, the size of the file is checked. If it is over the limit, moderators are displayed a message indicating that the channel is too large and they should remove extra playlist items, filters, and/or emotes. This is a partial solution for #421.
This commit is contained in:
parent
3689aafe3b
commit
709724efd4
|
@ -9,6 +9,8 @@ var path = require("path");
|
|||
var sio = require("socket.io");
|
||||
var db = require("../database");
|
||||
|
||||
const SIZE_LIMIT = 1048576;
|
||||
|
||||
/**
|
||||
* Previously, async channel functions were riddled with race conditions due to
|
||||
* an event causing the channel to be unloaded while a pending callback still
|
||||
|
@ -130,6 +132,23 @@ Channel.prototype.initModules = function () {
|
|||
self.logger.log("[init] Loaded modules: " + inited.join(", "));
|
||||
};
|
||||
|
||||
Channel.prototype.getDiskSize = function (cb) {
|
||||
if (this._getDiskSizeTimeout > Date.now()) {
|
||||
return cb(null, this._cachedDiskSize);
|
||||
}
|
||||
|
||||
var self = this;
|
||||
var file = path.join(__dirname, "..", "..", "chandump", self.uniqueName);
|
||||
fs.stat(file, function (err, stats) {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
self._cachedDiskSize = stats.size;
|
||||
cb(null, self._cachedDiskSize);
|
||||
});
|
||||
};
|
||||
|
||||
Channel.prototype.loadState = function () {
|
||||
var self = this;
|
||||
var file = path.join(__dirname, "..", "..", "chandump", self.uniqueName);
|
||||
|
@ -158,7 +177,7 @@ Channel.prototype.loadState = function () {
|
|||
if (!err) {
|
||||
var mb = stats.size / 1048576;
|
||||
mb = Math.floor(mb * 100) / 100;
|
||||
if (mb > 1) {
|
||||
if (mb > SIZE_LIMIT / 1048576) {
|
||||
Logger.errlog.log("Large chandump detected: " + self.uniqueName +
|
||||
" (" + mb + " MiB)");
|
||||
var msg = "This channel's state size has exceeded the memory limit " +
|
||||
|
@ -233,6 +252,20 @@ Channel.prototype.saveState = function () {
|
|||
* channels.
|
||||
*/
|
||||
var err = fs.writeFileSync(file, json);
|
||||
|
||||
// Check for large chandump and warn moderators/admins
|
||||
self.getDiskSize(function (err, size) {
|
||||
if (!err && size > SIZE_LIMIT && self.users) {
|
||||
self.users.forEach(function (u) {
|
||||
if (u.account.effectiveRank >= 2) {
|
||||
u.socket.emit("warnLargeChandump", {
|
||||
limit: SIZE_LIMIT,
|
||||
actual: size
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Channel.prototype.checkModules = function (fn, args, cb) {
|
||||
|
|
|
@ -1072,6 +1072,28 @@ Callbacks = {
|
|||
row.hide("fade", row.remove.bind(row));
|
||||
CHANNEL.emotes.splice(i, 1);
|
||||
}
|
||||
},
|
||||
|
||||
warnLargeChandump: function (data) {
|
||||
function toHumanReadable(size) {
|
||||
if (size > 1048576) {
|
||||
return Math.floor((size / 1048576) * 100) / 100 + "MiB";
|
||||
} else if (size > 1024) {
|
||||
return Math.floor((size / 1024) * 100) / 100 + "KiB";
|
||||
} else {
|
||||
return size + "B";
|
||||
}
|
||||
}
|
||||
|
||||
if ($("#chandumptoobig").length > 0) {
|
||||
$("#chandumptoobig").remove();
|
||||
}
|
||||
|
||||
errDialog("This channel currently exceeds the maximum size of " +
|
||||
toHumanReadable(data.limit) + " (channel size is " +
|
||||
toHumanReadable(data.actual) + "). Please reduce the size by removing " +
|
||||
"unneeded playlist items, filters, and/or emotes or else the channel will " +
|
||||
"be unable to load the next time it is reloaded").attr("id", "chandumptoobig");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue