| 241 | // --------------------------------------------------------------------------- |
| 242 | |
| 243 | function* bucketRanges( |
| 244 | since: Date, |
| 245 | bucket: Bucket |
| 246 | ): Generator<{ start: Date; end: Date }> { |
| 247 | const stepMs = bucket === 'day' ? 86_400_000 : 3600_000; |
| 248 | // Align the first bucket to the start of the day/hour. |
| 249 | const start = new Date(since); |
| 250 | if (bucket === 'day') { |
| 251 | start.setUTCHours(0, 0, 0, 0); |
| 252 | } else { |
| 253 | start.setUTCMinutes(0, 0, 0); |
| 254 | } |
| 255 | const now = Date.now(); |
| 256 | for (let t = start.getTime(); t < now; t += stepMs) { |
| 257 | yield { start: new Date(t), end: new Date(t + stepMs) }; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | async function deleteDuplicates(args: Args): Promise<void> { |
| 262 | const target = getReplicatedTableName(TABLE_NAMES.events); |