Update InstanceService, define cache keys

This commit is contained in:
Daniel Supernault 2022-03-12 23:32:31 -07:00
parent e925287824
commit 72918a4b09
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 11 additions and 6 deletions

View file

@ -7,6 +7,7 @@ use App\{Instance, Profile};
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use App\Services\InstanceService;
trait AdminInstanceController
{
@ -126,9 +127,9 @@ trait AdminInstanceController
break;
}
Cache::forget('instances:banned:domains');
Cache::forget('instances:unlisted:domains');
Cache::forget('instances:auto_cw:domains');
Cache::forget(InstanceService::CACHE_KEY_BANNED_DOMAINS);
Cache::forget(InstanceService::CACHE_KEY_UNLISTED_DOMAINS);
Cache::forget(InstanceService::CACHE_KEY_NSFW_DOMAINS);
return response()->json([]);
}

View file

@ -7,6 +7,10 @@ use App\Instance;
class InstanceService
{
const CACHE_KEY_BANNED_DOMAINS = 'instances:banned:domains';
const CACHE_KEY_UNLISTED_DOMAINS = 'instances:unlisted:domains';
const CACHE_KEY_NSFW_DOMAINS = 'instances:auto_cw:domains';
public static function getByDomain($domain)
{
return Cache::remember('pf:services:instance:by_domain:'.$domain, 3600, function() use($domain) {
@ -16,21 +20,21 @@ class InstanceService
public static function getBannedDomains()
{
return Cache::remember('instances:banned:domains', now()->addHours(12), function() {
return Cache::remember(self::CACHE_KEY_BANNED_DOMAINS, now()->addHours(12), function() {
return Instance::whereBanned(true)->pluck('domain')->toArray();
});
}
public static function getUnlistedDomains()
{
return Cache::remember('instances:unlisted:domains', now()->addHours(12), function() {
return Cache::remember(self::CACHE_KEY_UNLISTED_DOMAINS, now()->addHours(12), function() {
return Instance::whereUnlisted(true)->pluck('domain')->toArray();
});
}
public static function getNsfwDomains()
{
return Cache::remember('instances:auto_cw:domains', now()->addHours(12), function() {
return Cache::remember(self::CACHE_KEY_NSFW_DOMAINS, now()->addHours(12), function() {
return Instance::whereAutoCw(true)->pluck('domain')->toArray();
});
}