Add time-based filtering to Popular Links#228
Conversation
5d26dad to
6c8099a
Compare
There was a problem hiding this comment.
Pull request overview
Adds time-based filtering (7-day, 30-day, all-time) to the “Popular Links” section on the home page, backed by a new DB query path and an index to support efficient time-windowed aggregation.
Changes:
- Adds period filter links to the home page template and plumbs the selected period through
homeData. - Implements
SQLiteDB.LoadStatsSince(since)and wiresserveHometo use it for 7d/30d filters. - Updates DB schema with an index on
Stats(Created)and adds unit/integration tests for the new filtering behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
tmpl/home.html |
Adds UI filter links and active-state styling based on .Period. |
golink.go |
Reads ?period= and uses DB-backed stats for 7d/30d; passes .Period to the template. |
db.go |
Introduces LoadStatsSince to aggregate clicks since a given timestamp. |
schema.sql |
Adds an index on Stats.Created for time-based filtering queries. |
db_test.go |
Adds unit test coverage for LoadStatsSince. |
golink_test.go |
Adds integration test coverage for home page period filtering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mikeodr
left a comment
There was a problem hiding this comment.
My concerns largely align with the copilot check.
There's some cleanup missing in the queries, and doing a full load could be a bit more optimized.
Any screenshots of what the UIs look like would be helpful as well.
8472512 to
481475b
Compare
Allow users to filter the home page Popular Links table by 7 days, 30 days, or all time via a `?period=` query parameter. This uses a new `LoadStatsSince` DB method with a `WHERE Created >= ?` clause, backed by an index on `Stats.Created` for performance. Signed-off-by: David Carney <dfcarney@tailscale.com>
Avoid calling flushStats() on every ?period=7d/30d request, which would serialize home page requests under load. The periodic flush loop (every ~1 minute) keeps the DB sufficiently up to date. Signed-off-by: David Carney <dfcarney@tailscale.com>
Signed-off-by: David Carney <dfcarney@tailscale.com>
Signed-off-by: David Carney <dfcarney@tailscale.com>
481475b to
a54090a
Compare
|
Updated this branch and addressed the outstanding review feedback. Changes since the prior review:
Local verification:
|
Summary
LoadStatsSinceDB method backed by a singleStats/Linksjoin query and an index onStats(Created)for efficient time-filtered aggregationperiodas a bounded duration so pre-populated filters and arbitrary positive periods up to 365 days are supported without allowing unbounded full-history DB scansflushStats, avoiding serialization of home page requests under load (stats are at most ~1 minute stale via the periodic flush loop)Test plan
LoadStatsSinceindb_test.go, including stale stats for missing linksTestServeHomePeriodFilteringolink_test.gocovering all-time, 7d, 30d, arbitrary duration, and invalid period fallbackparseStatsPeriod, including bounds and overflow casesgo test ./...go test -race ./...