From 281443d7fee4a4782e05cbe9bd15639062371acd Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Mar 2022 23:15:47 -0700 Subject: [PATCH 1/5] Update SearchApiV2Service, filter banned instances --- app/Services/SearchApiV2Service.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Services/SearchApiV2Service.php b/app/Services/SearchApiV2Service.php index 41487f175..fdda0da07 100644 --- a/app/Services/SearchApiV2Service.php +++ b/app/Services/SearchApiV2Service.php @@ -85,6 +85,7 @@ class SearchApiV2Service $limit = $this->query->input('limit') ?? 20; $offset = $this->query->input('offset') ?? 0; $query = '%' . $this->query->input('q') . '%'; + $banned = InstanceService::getBannedDomains(); $results = Profile::select('profiles.*', 'followers.profile_id', 'followers.created_at') ->whereNull('status') ->leftJoin('followers', function($join) use($user) { @@ -97,9 +98,16 @@ class SearchApiV2Service ->offset($offset) ->limit($limit) ->get() + ->filter(function($profile) use ($banned) { + return in_array($profile->domain, $banned) == false; + }) ->map(function($res) { return AccountService::get($res['id']); - }); + }) + ->filter(function($account) { + return $account && isset($account['id']); + }) + ->values(); return $results; } From 1abcb7870a50cc9c34d5ea440e11e93b7271a76e Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Mar 2022 23:16:24 -0700 Subject: [PATCH 2/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e5d884bf..6841b3713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ - Updated presenter components, remove video poster attribute. ([4d612dfa](https://github.com/pixelfed/pixelfed/commit/4d612dfa)) - Improved reblog api performance ([3ef6c9fe](https://github.com/pixelfed/pixelfed/commit/3ef6c9fe)) - Updated ApiV1Controller, fix unlisted replies. ([c13bca76](https://github.com/pixelfed/pixelfed/commit/c13bca76)) +- Updated SearchApiV2Service, filter banned instances. ([281443d7](https://github.com/pixelfed/pixelfed/commit/281443d7)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.2 (2022-01-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.1...v0.11.2) From b91747b4bbff1af991a8e8e7f7a4775c482e39ae Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Mar 2022 23:24:33 -0700 Subject: [PATCH 3/5] Update DiscoverController, fix favourited state on memories --- app/Http/Controllers/DiscoverController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/DiscoverController.php b/app/Http/Controllers/DiscoverController.php index a72767ae9..7d8bf8edf 100644 --- a/app/Http/Controllers/DiscoverController.php +++ b/app/Http/Controllers/DiscoverController.php @@ -214,7 +214,9 @@ class DiscoverController extends Controller ->limit(20) ->pluck('status_id') ->map(function($id) { - return StatusService::get($id, false); + $status = StatusService::get($id, false); + $status['favourited'] = true; + return $status; }) ->filter(function($post) { return $post && isset($post['account']); From e925287824c49eed2c29dbf76dd2b38c28612caa Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Mar 2022 23:25:13 -0700 Subject: [PATCH 4/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6841b3713..98dae9e33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ - Improved reblog api performance ([3ef6c9fe](https://github.com/pixelfed/pixelfed/commit/3ef6c9fe)) - Updated ApiV1Controller, fix unlisted replies. ([c13bca76](https://github.com/pixelfed/pixelfed/commit/c13bca76)) - Updated SearchApiV2Service, filter banned instances. ([281443d7](https://github.com/pixelfed/pixelfed/commit/281443d7)) +- Updated DiscoverController, fix favourited state on memories. ([b91747b4](https://github.com/pixelfed/pixelfed/commit/b91747b4)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.2 (2022-01-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.1...v0.11.2) From 72918a4b09b95a6cd2f3f6ba0d410e5fce929c89 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 12 Mar 2022 23:32:31 -0700 Subject: [PATCH 5/5] Update InstanceService, define cache keys --- app/Http/Controllers/Admin/AdminInstanceController.php | 7 ++++--- app/Services/InstanceService.php | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Admin/AdminInstanceController.php b/app/Http/Controllers/Admin/AdminInstanceController.php index ddb6e777f..b24592c31 100644 --- a/app/Http/Controllers/Admin/AdminInstanceController.php +++ b/app/Http/Controllers/Admin/AdminInstanceController.php @@ -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([]); } diff --git a/app/Services/InstanceService.php b/app/Services/InstanceService.php index c95b6ac25..2b253e233 100644 --- a/app/Services/InstanceService.php +++ b/app/Services/InstanceService.php @@ -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(); }); }