Skip to content

Commit

Permalink
fix: Purge user profile cache upon discussion updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Jun 18, 2023
1 parent 2d802c3 commit 6215238
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Compatibility/FlarumTags/FlarumTagsPurgeMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected function processPurge(
return $response;
}

$response->getBody()->rewind();
$payload = $response->getBody()->getContents();
$payload = json_decode($payload, true);

Expand Down
17 changes: 17 additions & 0 deletions src/Middleware/LSCachePurgeMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ protected function processPurge(
if (($isPostUpdate && Arr::has($body, 'data.attributes.isHidden')) || ! $isPostUpdate) {
array_push($purgeParams, 'tag=default', 'tag=index', 'tag=discussions.index');
}

// User profile cache
$response->getBody()->rewind();
$payload = json_decode($response->getBody()->getContents(), true);

if (isset($payload, $payload['included'])) {
$userData = Arr::first($payload['included'], fn($value, $key) => $value['type'] === 'users');
if ($userData) {
$userId = $userData['id'];
$userName = Arr::get($userData, 'attributes.username');

array_push(
$purgeParams,
"tag=user_$userId", "tag=user_$userName", "tag=users_$userId", "tag=users_$userName"
);
}
}
}

if ($isPost) {
Expand Down

0 comments on commit 6215238

Please sign in to comment.