Skip to content

Commit 48521d6

Browse files
authored
Merge pull request #38143 from nextcloud/fix/generated-avatars-cache
Fix generated avatars cache
2 parents 25dd264 + 2a19753 commit 48521d6

3 files changed

Lines changed: 7 additions & 11 deletions

File tree

lib/private/Avatar/AvatarManager.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,8 @@ public function getAvatar(string $userId) : IAvatar {
160160
public function clearCachedAvatars() {
161161
$users = $this->config->getUsersForUserValue('avatar', 'generated', 'true');
162162
foreach ($users as $userId) {
163-
try {
164-
$folder = $this->appData->getFolder($userId);
165-
$folder->delete();
166-
} catch (NotFoundException $e) {
167-
$this->logger->debug("No cache for the user $userId. Ignoring...");
168-
}
169-
$this->config->setUserValue($userId, 'avatar', 'generated', 'false');
163+
// This also bumps the avatar version leading to cache invalidation in browsers
164+
$this->getAvatar($userId)->remove();
170165
}
171166
}
172167

lib/private/Repair/ClearGeneratedAvatarCache.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(IConfig $config, AvatarManager $avatarManager, IJobL
4242
}
4343

4444
public function getName(): string {
45-
return 'Clear every generated avatar on major updates';
45+
return 'Clear every generated avatar';
4646
}
4747

4848
/**
@@ -51,8 +51,9 @@ public function getName(): string {
5151
private function shouldRun(): bool {
5252
$versionFromBeforeUpdate = $this->config->getSystemValueString('version', '0.0.0.0');
5353

54-
// was added to 25.0.0.10
55-
return version_compare($versionFromBeforeUpdate, '25.0.0.10', '<=');
54+
// This job only runs if the server was on a version lower than or equal to 27.0.0 before the upgrade.
55+
// To clear the avatar cache again, bump the version to the currently released version (and change the operator to <= if it's not the master branch) and wait for the next release.
56+
return version_compare($versionFromBeforeUpdate, '27.0.0', '<');
5657
}
5758

5859
public function run(IOutput $output): void {

tests/lib/Repair/ClearGeneratedAvatarCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function shouldRunDataProvider() {
6161
['15.0.0.3', true],
6262
['13.0.5.2', true],
6363
['12.0.0.0', true],
64-
['26.0.0.1', false],
64+
['26.0.0.1', true],
6565
['15.0.0.2', true],
6666
['13.0.0.0', true],
6767
['27.0.0.5', false]

0 commit comments

Comments
 (0)