Scaling
Every view is its own row, so the views table grows with traffic. The table in
Start simple, scale when you need to lists what to switch on, and
retention and rollups keep the table from growing forever. At tens of millions of views a
month, partitioning lets a whole month go at once.
The repository has a benchmark suite that times the expensive paths against millions of seeded views on every supported database. The optional indexes below were measured with it.
Checking your setupviews:doctor looks at the setup and says what to fix.
Database indexesThe indexes the migrations add, and the optional ones views:doctor recommends as the table grows.
RetentionThe views table keeps every row, with the visitor id, the viewer and the context of each view.
RollupsRollups keep the counts of old views per bucket of time, so history outlives the views it was counted from and all-time counts read a few rows per model instead of every view.
The pairs tablePrecompute the pairs alsoViewed() and recommended() read, so they stay fast on large tables.
Purging bot viewsDelete the views that bursts of bot traffic recorded before the guard stopped them.
PartitioningPartitioned by viewed_at, a month of views goes with one DROP PARTITION instead of a delete per row.
Storing counts on your own tableKeep view counts in a column on your own table, so ordering and filtering by views read an index.
Buffering in RedisThe redis store replaces the insert during the request with one XADD to a Redis stream.