Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add travel type filter to caching #3042

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/DataProviders/CachedHafas.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getDepartures(Station $station, Carbon $when, int $duration = 15
// set duration longer than 15 minutes
$duration = $duration < 15 ? 30 : $duration;

$key = CacheKey::getHafasDeparturesKey($station->id, $when, $localtime);
$key = CacheKey::getHafasDeparturesKey($station->id, $when, $localtime, $type);

$departures = $this->remember(
$key,
Expand Down
13 changes: 10 additions & 3 deletions app/Helpers/CacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace App\Helpers;

use App\Enum\TravelType;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
Expand All @@ -24,7 +25,7 @@ class CacheKey
private const string STATISTICS_GLOBAL = 'StatisticsGlobal';
private const string HAFAS_TRIP = '_HafasTrip_%s_%s';
private const string HAFAS_STATIONS = '_HafasStations';
private const string HAFAS_DEPARTURES = '_HafasDepartures_%d_%s_%s';
private const string HAFAS_DEPARTURES = '_HafasDepartures_%d_%s_%s_%s';
private const string HAFAFS_STATION_RIL = '_HafasStationRil';
private const string HAFAS_STATIONS_FUZZY = '_HafasStationsFuzzy';
private const string HAFAS_CACHE_HIT = '_HafasCacheHit_%s';
Expand Down Expand Up @@ -53,8 +54,14 @@ public static function getHafasStationsKey(string $query): string {
return sprintf(self::FOR, self::HAFAS_STATIONS, $query);
}

public static function getHafasDeparturesKey(string $stationId, Carbon $when, bool $localtime): string {
return sprintf(self::HAFAS_DEPARTURES, $stationId, $when->toTimeString(), $localtime ? 'local' : 'utc');
public static function getHafasDeparturesKey(string $stationId, Carbon $when, bool $localtime, ?TravelType $type): string {
return sprintf(
self::HAFAS_DEPARTURES,
$stationId,
$when->toTimeString(),
$localtime ? 'local' : 'utc',
$type ? $type->value : 'all'
);
}

public static function getHafasByRilIdentifierKey(string $rilIdentifier): string {
Expand Down
Loading