diff --git a/config/pulse.php b/config/pulse.php index 810f13a9..25f653cb 100644 --- a/config/pulse.php +++ b/config/pulse.php @@ -23,6 +23,9 @@ 'database' => [ 'connection' => env('PULSE_DB_CONNECTION') ?? env('DB_CONNECTION') ?? 'mysql', + // TODO can we just use this instead of caring about Redis time? + // Then we can just use our time and this can be tweaked if needed + // to adjust for out of time sync issues. 'trim_after' => Interval::days(7), ], ], diff --git a/src/Ingests/Redis.php b/src/Ingests/Redis.php index 7ca1dfca..c152c2d1 100644 --- a/src/Ingests/Redis.php +++ b/src/Ingests/Redis.php @@ -2,6 +2,7 @@ namespace Laravel\Pulse\Ingests; +use Carbon\CarbonImmutable; use Carbon\CarbonInterval as Interval; use Illuminate\Support\Collection; use Laravel\Pulse\Contracts\Ingest; @@ -58,7 +59,7 @@ public function ingest(Collection $entries, Collection $updates): void */ public function trim(): void { - $this->connection->xtrim($this->stream, 'MINID', '~', $this->connection->streamIdAt($this->trimAfter()->invert())); + $this->connection->xtrim($this->stream, 'MINID', '~', (new CarbonImmutable)->subSeconds($this->trimAfter()->totalSeconds)->getTimestampMs()); } /** diff --git a/src/Redis.php b/src/Redis.php index 943fb3e1..be33eb23 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -76,18 +76,6 @@ public function pipeline(callable $closure): array }); } - /** - * Get the ID of the stream at a given time. - */ - public function streamIdAt(Interval $interval): string - { - $redisTime = $this->client()->time(); - - $redisTimestamp = (int) ($redisTime[0].substr($redisTime[1], 0, 3)); - - return (string) ($redisTimestamp + $interval->totalMilliseconds); - } - /** * The connections client. */