eventlog: only prune login and logout events
This commit is contained in:
@@ -90,6 +90,7 @@ exports = module.exports = {
|
||||
|
||||
const assert = require('assert'),
|
||||
database = require('./database.js'),
|
||||
debug = require('debug')('box:eventlog'),
|
||||
mysql = require('mysql'),
|
||||
notifications = require('./notifications.js'),
|
||||
safe = require('safetydance'),
|
||||
@@ -183,8 +184,25 @@ async function cleanup(options) {
|
||||
assert.strictEqual(typeof options, 'object');
|
||||
|
||||
const creationTime = options.creationTime;
|
||||
debug(`cleanup: pruning events. creationTime: ${creationTime.toString()}`);
|
||||
|
||||
const results = await database.query('SELECT * FROM eventlog WHERE creationTime <= ?', [ creationTime ]);
|
||||
// only these actions are pruned
|
||||
const actions = [
|
||||
exports.ACTION_USER_LOGIN,
|
||||
exports.ACTION_USER_LOGIN_GHOST,
|
||||
exports.ACTION_USER_LOGOUT,
|
||||
];
|
||||
|
||||
let query = `SELECT ${EVENTLOG_FIELDS} FROM eventlog WHERE creationTime <= ? AND (`;
|
||||
let data = [ creationTime ];
|
||||
actions.forEach(function (action, i) {
|
||||
query += ' action = ? ';
|
||||
data.push(action);
|
||||
if (i < actions.length-1) query += ' OR ';
|
||||
});
|
||||
query += ' ) ';
|
||||
|
||||
const results = await database.query(query, data);
|
||||
|
||||
for (const result of results) {
|
||||
await database.query('DELETE FROM notifications WHERE eventId=?', [ result.id ]); // remove notifications that reference the events as well
|
||||
|
||||
Reference in New Issue
Block a user