Gathers what the whole site did over a period, for the /community page and the digests' shared sections. The digests ask communityStatsOf for each reader's own period. The page reads the figures of the week and the month ending at the last refresh, which communityJob redoes every COMMUNITY_REFRESH_MINUTES, so a visit runs no query.

It also gathers the community feed (getCommunityFeed), the latest things done in public, which is read from the tables on each request: it has to show a dump the moment it is posted.

Functions

f
communityStatsOf(
from: Date,
to: Date
): CommunityStats

Returns what the site did from from to to: its most upvoted public dumps, who joined, the new public playlists, the chat's messages and the totals.

f
getCommunityFeed(): CommunityFeed

Returns the community feed for GET /api/community/feed: the latest events, read now, and the last week's figures as of the last refresh.

f
getCommunityStats(period: DigestCadence): CommunityStats

Returns the figures of period as of the last refresh, for GET /api/community, refreshing them first if there are none yet.

f
listCommunityEvents(): CommunityEvent[]

Returns the latest things done in public, newest first, FEED_MAX at most: the public dumps posted and playlists created, the comments and upvotes on public dumps, and who joined. A dump has one comment event and one upvote event at most, its latest, so that a thread or a popular dump doesn't fill the feed.

f
refreshCommunityStats(now?: Date): void

Recomputes the figures of each period, ending at now.

Variables

v
communityJob: Job

Refreshes the figures at startup, then every COMMUNITY_REFRESH_MINUTES. main.ts starts it.