Invalidate landing contact cache on user-side admin profile edits

When an admin updates their avatar, bio, or display name via the regular Settings UI (not the admin panel), AvatarOptimize and HomeSettings::homeUpdate previously only invalidated the per-profile caches. The api:v1:instance-data:contact key, which embeds the admin's account object on the landing page and at /api/v(1|2)/instance, remained cached for up to 7 days (also the source of many hours' headaches).

AvatarOptimize now also calls AccountService::del() (the underlying pf:services:account:<pid> cache, which had been left stale) and, if the profile backs the configured contact account, LandingCacheService::invalidateContact(). HomeSettings does the contact hit too.

The profileBacksContact helper mirrors the resolution order in LandingService::get(): prefer instance.admin.pid when set, else fall back to the first is_admin user.
pull/6656/head
Shannon Quinn 5 days ago
parent 19a7f7b128
commit 793d2c3ef3

@ -7,6 +7,7 @@ use App\EmailVerification;
use App\Mail\PasswordChange;
use App\Media;
use App\Services\AccountService;
use App\Services\LandingCacheService;
use App\Services\PronounService;
use App\Util\Lexer\Autolink;
use App\Util\Lexer\PrettyNumber;
@ -102,6 +103,9 @@ trait HomeSettings
Cache::forget('user:account:id:'.$user->id);
AccountService::forgetAccountSettings($profile->id);
AccountService::del($profile->id);
if (LandingCacheService::profileBacksContact((int) $profile->id)) {
LandingCacheService::invalidateContact();
}
return redirect('/settings/home')->with('status', 'Profile successfully updated!');
}

@ -4,6 +4,8 @@ namespace App\Jobs\AvatarPipeline;
use App\Avatar;
use App\Profile;
use App\Services\AccountService;
use App\Services\LandingCacheService;
use App\Util\Media\ImageDriverManager;
use Cache;
use Carbon\Carbon;
@ -96,6 +98,10 @@ class AvatarOptimize implements ShouldQueue
$avatar->last_processed_at = Carbon::now();
$avatar->save();
Cache::forget('avatar:'.$avatar->profile_id);
AccountService::del($avatar->profile_id);
if (LandingCacheService::profileBacksContact((int) $avatar->profile_id)) {
LandingCacheService::invalidateContact();
}
$this->deleteOldAvatar($avatar->media_path, $this->current);
if ((bool) config_cache('pixelfed.cloud_storage') && (bool) config_cache('instance.avatar.local_to_cloud')) {
@ -132,5 +138,9 @@ class AvatarOptimize implements ShouldQueue
$avatar->save();
Storage::delete($avatar->media_path);
Cache::forget('avatar:'.$avatar->profile_id);
AccountService::del($avatar->profile_id);
if (LandingCacheService::profileBacksContact((int) $avatar->profile_id)) {
LandingCacheService::invalidateContact();
}
}
}

Loading…
Cancel
Save