Skip to content

Instantly share code, notes, and snippets.

@barisusakli
Created November 19, 2021 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barisusakli/7bb8e631a4f452f95e80794f16f4a54e to your computer and use it in GitHub Desktop.
Save barisusakli/7bb8e631a4f452f95e80794f16f4a54e to your computer and use it in GitHub Desktop.
clean expires sessions
/* globals require, console, process */
'use strict';
const nconf = require('nconf');
nconf.file({
file: 'config.json',
});
nconf.defaults({
base_dir: __dirname,
views_dir: './build/public/templates',
upload_path: 'public/uploads',
});
const db = require('./src/database');
db.init(async (err) => {
await db.initSessionStore();
if (err) {
console.log(`NodeBB could not connect to your database. Error: ${err.message}`);
process.exit();
}
await removeExpiredSessions();
console.log('done');
process.exit();
});
async function removeExpiredSessions() {
const batch = require('./src/batch');
const user = require('./src/user');
const total = await db.sortedSetCard('users:joindate');
let counter = 0;
await batch.processSortedSet('users:joindate', async (uids) => {
await Promise.all(uids.map(uid => user.auth.getSessions(uid)));
counter += uids.length;
console.log(`${counter} / ${total}`);
}, {
batch: 500,
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment