Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Aug 15, 2023
1 parent 2f91313 commit 5675ae6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
3 changes: 3 additions & 0 deletions config/pulse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Ingests/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

/**
Expand Down
12 changes: 0 additions & 12 deletions src/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 5675ae6

Please sign in to comment.