Skip to content

Commit 141bb7d

Browse files
committed
#2936 Fixed some issues with the background caching of discover pages.
Not every page that is accessed often is cached properly. I added more cache to the cron job as a result.
1 parent e9d21af commit 141bb7d

File tree

9 files changed

+105
-71
lines changed

9 files changed

+105
-71
lines changed

app/Console/Commands/Scheduler/Discover/Cache.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function handle(DiscoverServiceInterface $discoverService, ExpansionServi
4343

4444
set_time_limit(3600);
4545

46+
// dump('Caching Discover pages');
4647
$this->info('Caching Discover pages');
4748

4849
// Disable cache so that we may refresh it
@@ -57,6 +58,7 @@ public function handle(DiscoverServiceInterface $discoverService, ExpansionServi
5758
// Refresh caches for all categories
5859
foreach ($expansions as $expansion) {
5960
/** @var Expansion $expansion */
61+
// dump(sprintf('- %s', $expansion->shortname));
6062
$this->info(sprintf('- %s', $expansion->shortname));
6163

6264
$expansion->load('dungeonsAndRaids');
@@ -79,28 +81,39 @@ public function handle(DiscoverServiceInterface $discoverService, ExpansionServi
7981
// :expansion/season/:season page. Remember, an expansion's season can have dungeons from any other expansion into it
8082
// The cache key changes when you assign a season to the DiscoverService so those pages need to be cached again
8183
foreach ($seasons as $season) {
84+
// dump(sprintf('- %s', $season->name));
8285
$this->info(sprintf('- %s', $season->name));
8386

84-
// foreach ($season->affixGroups ?? [] as $affixGroup) {
85-
// $this->info(sprintf('-- AffixGroup %s', $affixGroup->getTextAttribute()));
86-
// $discoverService->popularGroupedByDungeonByAffixGroup($affixGroup);
87-
// }
87+
// Only cache the current and next affix groups
88+
// The other affix groups are not queried as often so they can miss the cache
89+
$affixGroups = array_filter([
90+
$season->getCurrentAffixGroup(),
91+
$season->getNextAffixGroup(),
92+
]);
93+
94+
foreach ($affixGroups as $affixGroup) {
95+
// dump(sprintf('-- AffixGroup %s', $affixGroup->getTextAttribute()));
96+
$this->info(sprintf('-- AffixGroup %s', $affixGroup->getTextAttribute()));
97+
$discoverService->popularGroupedByDungeonByAffixGroup($affixGroup);
98+
}
8899

89100
$discoverService->popularBySeason($season);
90101
$discoverService->newBySeason($season);
91102

92103
$discoverService = $discoverService->withSeason($season);
93104
foreach ($season->dungeons()->active()->get() as $dungeon) {
94-
$this->info(sprintf('-- Dungeon %s', $dungeon->key));
105+
// dump(sprintf('-- Dungeon %s', $dungeon->key));
106+
$this->info(sprintf('-- Dungeon %s (%s)', __($dungeon->name), $dungeon->key));
95107

96108
$discoverService->popularByDungeon($dungeon);
97109
$discoverService->newByDungeon($dungeon);
98110
$discoverService->popularUsersByDungeon($dungeon);
99111

100-
// foreach ($season->affixGroups ?? [] as $affixGroup) {
101-
// $this->info(sprintf('--- AffixGroup %s', $affixGroup->getTextAttribute()));
102-
// $discoverService->popularGroupedByDungeonByAffixGroup($affixGroup);
103-
// }
112+
foreach ($affixGroups as $affixGroup) {
113+
// dump(sprintf('--- AffixGroup %s', $affixGroup->getTextAttribute()));
114+
$this->info(sprintf('--- AffixGroup %s', $affixGroup->getTextAttribute()));
115+
$discoverService->popularGroupedByDungeonByAffixGroup($affixGroup);
116+
}
104117
}
105118
}
106119

app/Http/Controllers/ProfileController.php

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -107,35 +107,36 @@ public function update(ProfileFormRequest $request, User $user, EchoServerHttpAp
107107

108108
// Send an event that the user's color has changed
109109
try {
110-
// Propagate changes to any channel the user may be in
111-
foreach ($echoServerHttpApiService->getChannels() as $name => $channel) {
112-
$context = null;
113-
114-
// If it's a route edit page
115-
if (str_contains($name, 'route-edit')) {
116-
$routeKey = str_replace(sprintf('presence-%s-route-edit.', config('app.type')), '', $name);
117-
/** @var DungeonRoute $context */
118-
$context = DungeonRoute::where('public_key', $routeKey)->first();
119-
} else if (str_contains($name, 'live-session')) {
120-
$routeKey = str_replace(sprintf('presence-%s-live-session.', config('app.type')), '', $name);
121-
/** @var LiveSession $context */
122-
$context = LiveSession::where('public_key', $routeKey)->first();
123-
}
124-
125-
// Only if we could find a route
126-
if ($context instanceof Model) {
127-
// Check if the user is in this channel..
128-
foreach ($echoServerHttpApiService->getChannelUsers($name) as $channelUser) {
129-
130-
if ($channelUser['id'] === $user->id) {
131-
// Broadcast that channel that our user's color has changed
132-
broadcast(new UserColorChangedEvent($context, $user));
133-
134-
break;
135-
}
136-
}
137-
}
138-
}
110+
// @TODO #2937
111+
// // Propagate changes to any channel the user may be in
112+
// foreach ($echoServerHttpApiService->getChannels() as $name => $channel) {
113+
// $context = null;
114+
//
115+
// // If it's a route edit page
116+
// if (str_contains($name, 'route-edit')) {
117+
// $routeKey = str_replace(sprintf('presence-%s-route-edit.', config('app.type')), '', $name);
118+
// /** @var DungeonRoute $context */
119+
// $context = DungeonRoute::where('public_key', $routeKey)->first();
120+
// } else if (str_contains($name, 'live-session')) {
121+
// $routeKey = str_replace(sprintf('presence-%s-live-session.', config('app.type')), '', $name);
122+
// /** @var LiveSession $context */
123+
// $context = LiveSession::where('public_key', $routeKey)->first();
124+
// }
125+
//
126+
// // Only if we could find a route
127+
// if ($context instanceof Model) {
128+
// // Check if the user is in this channel..
129+
// foreach ($echoServerHttpApiService->getChannelUsers($name) as $channelUser) {
130+
//
131+
// if ($channelUser['id'] === $user->id) {
132+
// // Broadcast that channel that our user's color has changed
133+
// broadcast(new UserColorChangedEvent($context, $user));
134+
//
135+
// break;
136+
// }
137+
// }
138+
// }
139+
// }
139140
} catch (Exception $exception) {
140141
report($exception);
141142

app/Models/Floor/Floor.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class Floor extends CacheModel implements MappingModelInterface
126126
1550, // The Shadowlands
127127
1490, // Mechagon
128128
1493, // Mechagon
129+
1525, // Revendreth
129130
2214, // The Ringing Deeps
130131
2248, // Isle of Dorn
131132
2274, // Khaz Algar

app/Service/Cache/CacheService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ public function __construct(private readonly CacheServiceLoggingInterface $log)
2222

2323
}
2424

25-
2625
private function getTtl(string $key): ?DateInterval
2726
{
2827
$cacheConfig = config('keystoneguru.cache');
2928

3029
return isset($cacheConfig[$key]) ? DateInterval::createFromDateString($cacheConfig[$key]['ttl']) : null;
3130
}
3231

32+
public function isCacheEnabled(): bool
33+
{
34+
return $this->cacheEnabled;
35+
}
36+
3337
public function setCacheEnabled(bool $cacheEnabled): CacheService
3438
{
3539
$this->cacheEnabled = $cacheEnabled;

app/Service/Cache/CacheServiceInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
interface CacheServiceInterface
88
{
9+
public function isCacheEnabled(): bool;
10+
911
public function setCacheEnabled(bool $cacheEnabled): self;
1012

1113
public function rememberWhen(bool $condition, string $key, mixed $value, mixed $ttl = null): mixed;

app/Service/Cache/DevCacheService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function get(string $key): mixed
2323
*/
2424
public function rememberWhen(bool $condition, string $key, mixed $value, mixed $ttl = null): mixed
2525
{
26-
$measureKey = sprintf('cacheservice-rememberwhen[%s]:%s', $key, $condition ? 'hit' : 'miss');
26+
$measureKey = sprintf('cacheservice-rememberwhen[%s]:%s', $key, $condition ? 'pass' : 'fail');
2727
Counter::increase($measureKey);
2828
Stopwatch::start($measureKey);
2929
$result = parent::rememberWhen($condition, $key, $value, $ttl);

app/Service/Cache/Traits/RemembersToFile.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
trait RemembersToFile
88
{
9-
private function rememberLocal(string $key, int $ttl, \Closure $compute)
9+
private function rememberLocal(string $key, int $ttl, \Closure $compute, bool $cacheEnabled = true): mixed
1010
{
11+
if (!$cacheEnabled) {
12+
return $compute();
13+
}
14+
15+
// Use a local cache store to avoid issues with file names
16+
// This is useful for temporary or development purposes
17+
// The key is prefixed with "local:" to avoid filename issues
1118
$localKey = "local:$key"; // avoids filename issues
1219

1320
return Cache::store('tmp_file')->remember($localKey, $ttl, $compute);

0 commit comments

Comments
 (0)