Skip to content

Commit

Permalink
Move expiry logic to event model
Browse files Browse the repository at this point in the history
Ensures that a meetup that has just started is displayed for two hours even if we clear the cache with a deployment before the two hours have passed; also cleans the code
  • Loading branch information
lukasbestle committed Jan 16, 2025
1 parent f239cd4 commit 4f5f523
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion site/controllers/meet.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// expire the cache 2h after the next upcoming event starts
if ($next = $upcoming->sortBy('date', 'asc')->first()) {
$time = $next->datetime()->getTimestamp() + (60 * 60 * 2);
$time = $next->expiryTime();
$kirby->response()->expires($time);
$kirby->response()->header('Expires', gmdate('D, d M Y H:i:s T', $time));
}
Expand Down
8 changes: 7 additions & 1 deletion site/models/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public function datetime(): DateTime
);
}

public function expiryTime(): int
{
// expire each event two hours after it started
return $this->datetime()->getTimestamp() + (60 * 60 * 2);
}

public function icon(): string
{
return parent::icon()->or(match (true) {
Expand All @@ -35,7 +41,7 @@ public function isMeetup(): bool

public function isUpcoming(): bool
{
return $this->datetime()->getTimestamp() >= time();
return $this->expiryTime() >= time();
}

public function shortTitle(): Field
Expand Down

0 comments on commit 4f5f523

Please sign in to comment.