summaryrefslogtreecommitdiff
path: root/cli/recount-stats.js
blob: 84cb5d0f5757229fdc74e3252372b3083f23423e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const { default: Note } = require('../built/models/note');
const { default: Meta } = require('../built/models/meta');
const { default: User } = require('../built/models/user');

async function main() {
	const meta = await Meta.findOne({});

	const notesCount = await Note.count();

	const usersCount = await User.count();

	const originalNotesCount = await Note.count({
		'_user.host': null
	});

	const originalUsersCount = await User.count({
		host: null
	});

	const stats = {
		notesCount,
		usersCount,
		originalNotesCount,
		originalUsersCount
	};

	if (meta) {
		await Meta.update({}, {
			$set: {
				stats
			}
		});
	} else {
		await Meta.insert({
			stats
		});
	}
}

main().then(() => {
	console.log('done');
}).catch(console.error);