Skip to content

Commit 54f566b

Browse files
committed
perf(clicks): default time-series granularity to hours
Sparse per-link traffic degenerates 1-hour bucket spans into one bucket per click. New deploys get hours (30-day spans); existing collections keep their setting and need a one-time collMod, since granularity can only be coarsened.
1 parent fe29826 commit 54f566b

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

repositories/indexes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ async def ensure_indexes(
7272
timeseries={
7373
"timeField": "clicked_at",
7474
"metaField": "meta",
75-
"granularity": "seconds",
75+
# "hours" spans buckets over 30 days. Most links get sparse
76+
# clicks, so finer granularity degenerates into one bucket
77+
# per click. Existing deploys need a one-time collMod to
78+
# match (the transition is one-way, coarser only).
79+
"granularity": "hours",
7680
},
7781
)
7882
except (CollectionInvalid, OperationFailure) as e:

tests/unit/repositories/test_indexes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async def test_ensure_indexes_creates_timeseries_collection(self):
145145
timeseries={
146146
"timeField": "clicked_at",
147147
"metaField": "meta",
148-
"granularity": "seconds",
148+
"granularity": "hours",
149149
},
150150
)
151151

0 commit comments

Comments
 (0)