summaryrefslogtreecommitdiff
path: root/src/daemons/notes-stats-child.ts
blob: b60f5badfd12323d8e4d4eac9257620523612e27 (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
import { MoreThanOrEqual, getRepository } from 'typeorm';
import { Note } from '../models/entities/note';
import { initDb } from '../db/postgre';

const interval = 5000;

initDb().then(() => {
	const Notes = getRepository(Note);

	async function tick() {
		const [all, local] = await Promise.all([Notes.count({
			createdAt: MoreThanOrEqual(new Date(Date.now() - interval))
		}), Notes.count({
			createdAt: MoreThanOrEqual(new Date(Date.now() - interval)),
			userHost: null
		})]);

		const stats = {
			all, local
		};

		process.send!(stats);
	}

	tick();

	setInterval(tick, interval);
});