Fixed DbExpire with NeDB.

This commit is contained in:
Ylian Saint-Hilaire 2020-07-08 14:29:32 -07:00
parent 49e49db186
commit bd660a7394
3 changed files with 23 additions and 18 deletions

6
db.js
View File

@ -681,13 +681,13 @@ module.exports.CreateDB = function (parent, func) {
obj.eventsfile.persistence.setAutocompactionInterval(86400000); // Compact once a day
obj.eventsfile.ensureIndex({ fieldName: 'ids' }); // TODO: Not sure if this is a good index, this is a array field.
obj.eventsfile.ensureIndex({ fieldName: 'nodeid', sparse: true });
obj.eventsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: 60 * 60 * 24 * 20 }); // Limit the power event log to 20 days (Seconds * Minutes * Hours * Days)
obj.eventsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expireEventsSeconds });
// Setup the power collection and setup indexes
obj.powerfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-power.db'), autoload: true });
obj.powerfile.persistence.setAutocompactionInterval(86400000); // Compact once a day
obj.powerfile.ensureIndex({ fieldName: 'nodeid' });
obj.powerfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: 60 * 60 * 24 * 10 }); // Limit the power event log to 10 days (Seconds * Minutes * Hours * Days)
obj.powerfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expirePowerEventsSeconds });
// Setup the SMBIOS collection
obj.smbiosfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-smbios.db'), autoload: true });
@ -695,7 +695,7 @@ module.exports.CreateDB = function (parent, func) {
// Setup the server stats collection and setup indexes
obj.serverstatsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-stats.db'), autoload: true });
obj.serverstatsfile.persistence.setAutocompactionInterval(86400000); // Compact once a day
obj.serverstatsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: 60 * 60 * 24 * 30 }); // Limit the server stats log to 30 days (Seconds * Minutes * Hours * Days)
obj.serverstatsfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expireServerStatsSeconds });
obj.serverstatsfile.ensureIndex({ fieldName: 'expire', expireAfterSeconds: 0 }); // Auto-expire events
// Setup plugin info collection

View File

@ -5284,7 +5284,7 @@
"en": "ChatSession",
"nl": "Chat sessie",
"xloc": [
"messenger.handlebars->13->14"
"messenger.handlebars->13->16"
]
},
{
@ -6522,7 +6522,7 @@
"ru": "Подключено.",
"zh-chs": "連接的。",
"xloc": [
"messenger.handlebars->13->12"
"messenger.handlebars->13->14"
]
},
{
@ -8999,7 +8999,7 @@
"zh-chs": "下載",
"xloc": [
"download.handlebars->container->page_content->column_l->1",
"messenger.handlebars->13->10"
"messenger.handlebars->13->11"
]
},
{
@ -10675,7 +10675,7 @@
"ru": "Ошибка: Не указан ключ подключения.",
"zh-chs": "錯誤:未指定連接密鑰。",
"xloc": [
"messenger.handlebars->13->13"
"messenger.handlebars->13->15"
]
},
{
@ -28593,7 +28593,7 @@
"ru": "В ожидании другой стороны...",
"zh-chs": "正在等待其他用戶...",
"xloc": [
"messenger.handlebars->13->11"
"messenger.handlebars->13->13"
]
},
{
@ -29942,6 +29942,13 @@
"default.handlebars->27->454"
]
},
{
"en": "bytes",
"xloc": [
"messenger.handlebars->13->10",
"messenger.handlebars->13->12"
]
},
{
"cs": "klikněte zde",
"de": "hier klicken",

View File

@ -62,7 +62,7 @@
var webrtcconfiguration = '{{{webrtconfig}}}';
if (webrtcconfiguration == '') { webrtcconfiguration = null; } else { try { webrtcconfiguration = JSON.parse(decodeURIComponent(webrtcconfiguration)); } catch (ex) { console.log('Invalid WebRTC config: "' + webrtcconfiguration + '".'); webrtcconfiguration = null; } }
var windowFocus = true;
var chatTestSession = new Date().toString() + '\r\n';
var chatTextSession = new Date().toString() + '\r\n';
// File transfer state
var fileUploads = [];
@ -121,7 +121,7 @@
}
function onUserInputFocus(x) { userInputFocus = x; }
function displayClear() { chatTestSession = new Date().toString() + '\r\n'; QH('xmsg', ''); cancelAllFileTransfers(); fileUploads = [], fileDownloads = {}; }
function displayClear() { chatTextSession = new Date().toString() + '\r\n'; QH('xmsg', ''); cancelAllFileTransfers(); fileUploads = [], fileDownloads = {}; }
// Polyfill FileReader if needed
if (!FileReader.prototype.readAsBinaryString) {
@ -156,7 +156,7 @@
// Display a control message
function displayControl(msg) {
chatTestSession += ("Control" + '> ' + msg + '\r\n');
chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Control" + '> ' + msg + '\r\n');
QA('xmsg', '<div style="clear:both"><div style="color:gray;float:left;margin-bottom:2px">' + EscapeHtml(msg) + '</div><div></div></div>');
Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;//Q('xmsg').scrollHeight;
}
@ -171,7 +171,7 @@
// Display a message from the remote user
function displayRemote(msg) {
chatTestSession += ("Remote" + '> ' + msg + '\r\n');
chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Remote" + '> ' + msg + '\r\n');
QA('xmsg', '<div style="clear:both"><div class="remoteBubble">' + EscapeHtml(msg) + '</div><div></div></div>');
Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
@ -194,7 +194,7 @@
var outtext = Q('xouttext').value;
if (outtext.length > 0) {
Q('xouttext').value = '';
chatTestSession += ("Local" + '> ' + outtext + '\r\n');
chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Local" + '> ' + outtext + '\r\n');
QA('xmsg', '<div style="clear:both"><div class="localBubble">' + EscapeHtml(outtext) + '</div><div></div></div>');
Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
send({ action: 'chat', msg: outtext });
@ -429,8 +429,7 @@
if (state != 2) return;
file.id = Math.random();
fileUploads.push(file);
console.log(file);
chatTestSession += ("Upload" + '> ' + file.name + '\r\n');
chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Upload" + '> ' + file.name + ' (' + file.size + ' ' + "bytes" + ')\r\n');
QA('xmsg', '<div style="clear:both"></div><div id="FILEUP-' + file.id + '" class="localBubble" style="width:240px;cursor:pointer" onclick="cancelFileTransfer(\'' + file.id + '\')"><div id="FILEUP-ICON-' + file.id + '" class="fileicon" style="float:left;width:32px;height:32px"></div><div><div id="FILEUP-NAME-' + file.id + '" style="height:16px;overflow:hidden;white-space:nowrap;" title="' + file.name + '">' + file.name + '</div><div style="width:200px;background-color:lightgray;margin-left:32px;border-radius:3px;margin-top:3px;height:11px"><div id="FILEUP-PROGRESS-' + file.id + '" style="width:0px;background-color:green;border-radius:3px;height:11px">&nbsp;</div></div></div></div>');
Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
send({ action: 'file', size: file.size, id: file.id, type: file.type, name: file.name });
@ -440,8 +439,7 @@
function startFileDownload(file) {
if (state != 2) return;
fileDownloads[file.id] = file;
console.log(file);
chatTestSession += ("Download" + '> ' + file.name + '\r\n');
chatTextSession += ((new Date()).toLocaleTimeString() + ' - ' + "Download" + '> ' + file.name + ' (' + file.size + ' ' + "bytes" + ')\r\n');
QA('xmsg', '<div style="clear:both"></div><div id="FILEUP-' + file.id + '" class="remoteBubble" style="width:240px;cursor:pointer" onclick="saveFileTransfer(\'' + file.id + '\')"><div id="FILEUP-ICON-' + file.id + '" class="fileicon" style="float:left;width:32px;height:32px"></div><div><div id="FILEUP-NAME-' + file.id + '" style="height:16px;overflow:hidden;white-space:nowrap;" title="' + file.name + '">' + file.name + '</div><div style="width:200px;background-color:lightgray;margin-left:32px;border-radius:3px;margin-top:3px;height:11px"><div id="FILEUP-PROGRESS-' + file.id + '" style="width:0px;background-color:green;border-radius:3px;height:11px">&nbsp;</div></div></div></div>');
Q('xmsgparent').scrollTop = Q('xmsgparent').scrollHeight;
}
@ -646,7 +644,7 @@
}
function saveChatSession() {
saveAs(data2blob(chatTestSession), "ChatSession");
saveAs(data2blob(chatTextSession), "ChatSession");
}
start();