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.
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.
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.
Returns the figures of period as of the last refresh, for
GET /api/community, refreshing them first if there are none yet.
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.
Recomputes the figures of each period, ending at now.
Refreshes the figures at startup, then every
COMMUNITY_REFRESH_MINUTES. main.ts starts it.
Usage
import * as mod from "api/services/community-service.ts";