From fe6787f75e96f8e3607caf673e64d469c3cfba24 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 26 Aug 2022 01:55:51 -0600 Subject: [PATCH 1/4] Update AdminSettingsController, fix cache invalidation when updating rules --- app/Http/Controllers/Admin/AdminSettingsController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/AdminSettingsController.php b/app/Http/Controllers/Admin/AdminSettingsController.php index 6665335c0..c85a260e3 100644 --- a/app/Http/Controllers/Admin/AdminSettingsController.php +++ b/app/Http/Controllers/Admin/AdminSettingsController.php @@ -75,6 +75,8 @@ trait AdminSettingsController unset($json[$index]); $json = json_encode(array_values($json)); ConfigCacheService::put('app.rules', $json); + Cache::forget('api:v1:instance-data:rules'); + Cache::forget('api:v1:instance-data-response-v1'); return 200; } @@ -173,7 +175,7 @@ trait AdminSettingsController ConfigCacheService::put('app.rules', json_encode(array_values($json))); } Cache::forget('api:v1:instance-data:rules'); - Cache::forget('api:v1:instance-data-response'); + Cache::forget('api:v1:instance-data-response-v1'); } if($request->filled('account_autofollow_usernames')) { From 533f7165a990da6e415314b0395bfa916038a96e Mon Sep 17 00:00:00 2001 From: Daniel Supernault <877217+dansup@users.noreply.github.com> Date: Sun, 28 Aug 2022 06:28:46 -0600 Subject: [PATCH 2/4] Update SearchApiService, improve account/webfinger results --- app/Services/SearchApiV2Service.php | 42 +++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/app/Services/SearchApiV2Service.php b/app/Services/SearchApiV2Service.php index 66f81f14a..575cfe0da 100644 --- a/app/Services/SearchApiV2Service.php +++ b/app/Services/SearchApiV2Service.php @@ -35,7 +35,7 @@ class SearchApiV2Service if($query->has('resolve') && $query->resolve == true && ( Str::startsWith($q, 'https://') || - Str::substrCount($q, '@') == 2) + Str::substrCount($q, '@') >= 1) ) { return $this->resolveQuery(); } @@ -81,13 +81,21 @@ class SearchApiV2Service ]; } - protected function accounts() + protected function accounts($initalQuery = false) { $mastodonMode = self::$mastodonMode; $user = request()->user(); $limit = $this->query->input('limit') ?? 20; $offset = $this->query->input('offset') ?? 0; - $query = '%' . $this->query->input('q') . '%'; + $rawQuery = $initalQuery ? $initalQuery : $this->query->input('q'); + $query = '%' . $rawQuery . '%'; + if(Str::substrCount($rawQuery, '@') >= 1 && Str::contains($rawQuery, config('pixelfed.domain.app'))) { + $deliminatorCount = Str::substrCount($rawQuery, '@'); + $query = explode('@', $rawQuery)[$deliminatorCount == 1 ? 0 : 1]; + } + if(Str::substrCount($rawQuery, '@') == 1 && substr($rawQuery, 0, 1) == '@') { + $query = substr($rawQuery, 1) . '%'; + } $banned = InstanceService::getBannedDomains(); $results = Profile::select('profiles.*', 'followers.profile_id', 'followers.created_at') ->whereNull('status') @@ -173,8 +181,17 @@ class SearchApiV2Service protected function resolveQuery() { + $default = [ + 'accounts' => [], + 'hashtags' => [], + 'statuses' => [], + ]; $mastodonMode = self::$mastodonMode; $query = urldecode($this->query->input('q')); + if(substr($query, 0, 1) === '@' && !Str::contains($query, '.')) { + $default['accounts'] = $this->accounts(substr($query, 1)); + return $default; + } if(Helpers::validateLocalUrl($query)) { if(Str::contains($query, '/p/')) { return $this->resolveLocalStatus(); @@ -182,15 +199,24 @@ class SearchApiV2Service return $this->resolveLocalProfile(); } } else { - $default = [ - 'accounts' => [], - 'hashtags' => [], - 'statuses' => [], - ]; if(!Helpers::validateUrl($query) && strpos($query, '@') == -1) { return $default; } + if(Str::substrCount($query, '@') == 1 && strpos($query, '@') !== 0) { + try { + $res = WebfingerService::lookup('@' . $query, $mastodonMode); + } catch (\Exception $e) { + return $default; + } + if($res && isset($res['id'])) { + $default['accounts'][] = $res; + return $default; + } else { + return $default; + } + } + if(Str::substrCount($query, '@') == 2) { try { $res = WebfingerService::lookup($query, $mastodonMode); From 949b7bb6ea8fc4ee411bc8bfda9fd150071f1af1 Mon Sep 17 00:00:00 2001 From: Daniel Supernault <877217+dansup@users.noreply.github.com> Date: Mon, 29 Aug 2022 20:06:59 -0600 Subject: [PATCH 3/4] Update NotificationService, fix account attribute --- app/Services/NotificationService.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Services/NotificationService.php b/app/Services/NotificationService.php index 264f9df31..139b13a69 100644 --- a/app/Services/NotificationService.php +++ b/app/Services/NotificationService.php @@ -107,7 +107,9 @@ class NotificationService { foreach($ids as $id) { $n = self::rewriteMastodonTypes(self::getNotification($id)); if($n != null && in_array($n['type'], self::MASTODON_TYPES)) { - $n['account'] = AccountService::getMastodon($n['account']['id']); + if(isset($n['account'])) { + $n['account'] = AccountService::getMastodon($n['account']['id']); + } if(isset($n['relationship'])) { unset($n['relationship']); @@ -135,7 +137,9 @@ class NotificationService { foreach($ids as $id) { $n = self::rewriteMastodonTypes(self::getNotification($id)); if($n != null && in_array($n['type'], self::MASTODON_TYPES)) { - $n['account'] = AccountService::getMastodon($n['account']['id']); + if(isset($n['account'])) { + $n['account'] = AccountService::getMastodon($n['account']['id']); + } if(isset($n['relationship'])) { unset($n['relationship']); From 1f70263885b690a46a40c8d7c8ccbe3926ff2116 Mon Sep 17 00:00:00 2001 From: Daniel Supernault <877217+dansup@users.noreply.github.com> Date: Mon, 29 Aug 2022 20:07:37 -0600 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a01ddb061..8638c4174 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,10 @@ - Add instance post/profile embed config setting ([7734dc03](https://github.com/pixelfed/pixelfed/commit/7734dc03)) - Remove remote posts from NetworkTimelineService when processing Tombstones ([2e4f2377](https://github.com/pixelfed/pixelfed/commit/2e4f2377)) - Limit NotificationService to 400 items ([f6ed560e](https://github.com/pixelfed/pixelfed/commit/f6ed560e)) +- Refactor discover accounts endpoint, cache popular accounts and remove following check as most invocations are from new accounts ([016b11f3](https://github.com/pixelfed/pixelfed/commit/016b11f3)) +- Fix cache invalidation in AdminSettingsController when updating rules ([fe6787f7](https://github.com/pixelfed/pixelfed/commit/fe6787f7)) +- Update SearchApiService, improve account/webfinger results ([533f7165](https://github.com/pixelfed/pixelfed/commit/533f7165)) +- Update NotificationService, fix account attribute ([949b7bb6](https://github.com/pixelfed/pixelfed/commit/949b7bb6)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.3 (2022-05-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.2...v0.11.3)