Created
November 19, 2021 00:56
-
-
Save barisusakli/7bb8e631a4f452f95e80794f16f4a54e to your computer and use it in GitHub Desktop.
clean expires sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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