|
37 | 37 | * schema_version: int, |
38 | 38 | * exported_at: string, |
39 | 39 | * profile: array<string, bool|int|string|null>, |
40 | | - * active_days: array<mixed>, |
| 40 | + * active_days: Generator<int, string>, |
41 | 41 | * commits: Generator<int, array<string, mixed>>, |
42 | 42 | * polls: Generator<int, ExportPoll>, |
43 | 43 | * poll_votes: Generator<int, ExportPollVote>, |
@@ -106,7 +106,7 @@ public function handle(User $user): array |
106 | 106 | 'created_at' => $user->created_at->toIso8601String(), |
107 | 107 | 'updated_at' => $user->updated_at->toIso8601String(), |
108 | 108 | ], |
109 | | - 'active_days' => DB::table('user_active_days')->where('user_id', $user->id)->oldest('seen_at')->pluck('seen_at')->all(), |
| 109 | + 'active_days' => $this->activeDays($user), |
110 | 110 | 'commits' => $this->commits($user), |
111 | 111 | 'polls' => $this->polls($user), |
112 | 112 | 'poll_votes' => $this->pollVotes($user), |
@@ -244,6 +244,22 @@ private function pollVotes(User $user): Generator |
244 | 244 | } |
245 | 245 | } |
246 | 246 |
|
| 247 | + /** |
| 248 | + * The days the user was seen, oldest first. They are read while the export streams, after the request asking for it |
| 249 | + * was recorded, so an export that is the first visit of the day includes that day. |
| 250 | + * |
| 251 | + * @return Generator<int, string> |
| 252 | + */ |
| 253 | + private function activeDays(User $user): Generator |
| 254 | + { |
| 255 | + /** @var LazyCollection<int, object{seen_at: string}> $days */ |
| 256 | + $days = DB::table('user_active_days')->where('user_id', $user->id)->oldest('seen_at')->cursor(); |
| 257 | + |
| 258 | + foreach ($days as $day) { |
| 259 | + yield $day->seen_at; |
| 260 | + } |
| 261 | + } |
| 262 | + |
247 | 263 | /** |
248 | 264 | * @return Generator<int, string> |
249 | 265 | */ |
|
0 commit comments