#804

Cache the heavy report so the dashboard stops lagging

A dashboard shows «event counts per user» and refreshes every 30 seconds. On a 100M-row table this query takes 8 seconds — too slow for every dashboard open. Cache the result in a materialized view and refresh it on a schedule. Build an events table with id, user_id, and ts, insert five rows. Create a materialized view named events_per_user that holds the per-user event count. Add one more event to events, refresh the materialized view — after refreshing the numbers should reflect the new state.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.

nuser_id
41
22

Your query result will appear here

No starting schema

This task starts with no tables — you'll create them via CREATE TABLE.