mirror of
https://github.com/Xevion/banner.git
synced 2026-01-31 06:23:37 -06:00
Implements POST /api/timeline endpoint that aggregates enrollment by subject over 15-minute slots, filtering courses by their actual meeting times. Includes ISR-style schedule cache with hourly background refresh using stale-while-revalidate pattern, database indexes for efficient queries, and frontend refactor to dynamically discover subjects from API.
14 lines
658 B
SQL
14 lines
658 B
SQL
-- Indexes for the timeline aggregation endpoint.
|
|
-- The query buckets course_metrics by 15-minute intervals, joins to courses
|
|
-- for subject, and aggregates enrollment. These indexes support efficient
|
|
-- time-range scans and the join.
|
|
|
|
-- Primary access pattern: scan course_metrics by timestamp range
|
|
CREATE INDEX IF NOT EXISTS idx_course_metrics_timestamp
|
|
ON course_metrics (timestamp);
|
|
|
|
-- Composite index for the DISTINCT ON (bucket, course_id) ordered by timestamp DESC
|
|
-- to efficiently pick the latest metric per course per bucket.
|
|
CREATE INDEX IF NOT EXISTS idx_course_metrics_course_timestamp
|
|
ON course_metrics (course_id, timestamp DESC);
|