From c1d127210582a7bc5fca4f5f49c42aae40830ca5 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 May 2023 21:01:59 -0600 Subject: [PATCH 1/7] Update pixelfed config, disable cloud ip bans by default --- config/pixelfed.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/pixelfed.php b/config/pixelfed.php index e63d886f2..a40dc2d5b 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -261,10 +261,10 @@ return [ 'enabled' => env('PF_BOUNCER_ENABLED', false), 'cloud_ips' => [ - 'ban_logins' => env('PF_BOUNCER_BAN_CLOUD_LOGINS', true), - 'ban_signups' => env('PF_BOUNCER_BAN_CLOUD_SIGNUPS', true), - 'ban_api' => env('PF_BOUNCER_BAN_CLOUD_API', true), - 'ban_api_strict_mode' => env('PF_BOUNCER_BAN_CLOUD_API_STRICT_MODE', true), + 'ban_logins' => env('PF_BOUNCER_BAN_CLOUD_LOGINS', false), + 'ban_signups' => env('PF_BOUNCER_BAN_CLOUD_SIGNUPS', false), + 'ban_api' => env('PF_BOUNCER_BAN_CLOUD_API', false), + 'ban_api_strict_mode' => env('PF_BOUNCER_BAN_CLOUD_API_STRICT_MODE', false), ], ], From 55293e9ee6416b7dd79bf11cb95bbb4f109747b1 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 May 2023 21:02:13 -0600 Subject: [PATCH 2/7] Update changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 988bb6448..e3f606f37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,12 @@ - Add php 8.2 support. Bump laravel version, v9 => v10 ([fb4ac4eb](https://github.com/pixelfed/pixelfed/commit/fb4ac4eb)) - New media:fix-nonlocal-driver command. Fixes s3 media created with invalid FILESYSTEM_DRIVER=s3 configuration ([672cccd4](https://github.com/pixelfed/pixelfed/commit/672cccd4)) - New landing page design ([09c0032b](https://github.com/pixelfed/pixelfed/commit/09c0032b)) -- Add cloud ip bans to BouncerService ([50ab2e20](https://github.com/pixelfed/pixelfed/commit/50ab2e20)) +- Add cloud ip bans to BouncerService (disabled by default) ([50ab2e20](https://github.com/pixelfed/pixelfed/commit/50ab2e20)) - Redesigned Admin Dashboard Reports/Moderation ([c6cc6327](https://github.com/pixelfed/pixelfed/commit/c6cc6327)) +### Fixes +- Fixed `violates check constraint "statuses_visibility_check"` bug affecting postgres instances + various api endpoints ([79b6a17e](https://github.com/pixelfed/pixelfed/commit/79b6a17e)) + ### Updates - Update ApiV1Controller, fix blocking remote accounts. Closes #4256 ([8e71e0c0](https://github.com/pixelfed/pixelfed/commit/8e71e0c0)) - Update ComposeController, fix postgres location search. Closes #4242 and #4239 ([64a4a006](https://github.com/pixelfed/pixelfed/commit/64a4a006)) From 055aa6b39fe34f83e2ba8c6fad1b3a3f6f69ea4a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 May 2023 23:26:37 -0600 Subject: [PATCH 3/7] Update ApiV1Controller and DiscoverController, fix postgres hashtag search --- app/Http/Controllers/Api/ApiV1Controller.php | 12 +++++++++--- app/Http/Controllers/DiscoverController.php | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index b9011e595..37412c489 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -3245,9 +3245,15 @@ class ApiV1Controller extends Controller 'limit' => 'nullable|integer|max:100' ]); - $tag = Hashtag::whereName($hashtag) - ->orWhere('slug', $hashtag) - ->first(); + if(config('database.default') === 'pgsql') { + $tag = Hashtag::where('name', 'ilike', $hashtag) + ->orWhere('slug', 'ilike', $hashtag) + ->first(); + } else { + $tag = Hashtag::whereName($hashtag) + ->orWhere('slug', $hashtag) + ->first(); + } if(!$tag) { return response()->json([]); diff --git a/app/Http/Controllers/DiscoverController.php b/app/Http/Controllers/DiscoverController.php index 3dab2b40b..4bb7277a4 100644 --- a/app/Http/Controllers/DiscoverController.php +++ b/app/Http/Controllers/DiscoverController.php @@ -61,7 +61,12 @@ class DiscoverController extends Controller $end = $page > 1 ? $page * 9 : 0; $tag = $request->input('hashtag'); - $hashtag = Hashtag::whereName($tag)->firstOrFail(); + if(config('database.default') === 'pgsql') { + $hashtag = Hashtag::where('name', 'ilike', $tag)->firstOrFail(); + } else { + $hashtag = Hashtag::whereName($tag)->firstOrFail(); + } + if($hashtag->is_banned == true) { return []; } From 867cbc757c46cabd4b0f08a90133f70f5a250e35 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 May 2023 23:31:16 -0600 Subject: [PATCH 4/7] Update StatusTagsPipeline, deduplicate hashtags on postgres --- .../StatusPipeline/StatusTagsPipeline.php | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/Jobs/StatusPipeline/StatusTagsPipeline.php b/app/Jobs/StatusPipeline/StatusTagsPipeline.php index 1f7969555..a72e6d50e 100644 --- a/app/Jobs/StatusPipeline/StatusTagsPipeline.php +++ b/app/Jobs/StatusPipeline/StatusTagsPipeline.php @@ -71,11 +71,24 @@ class StatusTagsPipeline implements ShouldQueue } } - $hashtag = Hashtag::firstOrCreate([ - 'slug' => str_slug($name) - ], [ - 'name' => $name - ]); + if(config('database.default') === 'pgsql') { + $hashtag = Hashtag::where('name', 'ilike', $name) + ->orWhere('slug', 'ilike', str_slug($name)) + ->first(); + + if(!$hashtag) { + $hashtag = new Hashtag; + $hashtag->name = $name; + $hashtag->slug = str_slug($name); + $hashtag->save(); + } + } else { + $hashtag = Hashtag::firstOrCreate([ + 'slug' => str_slug($name) + ], [ + 'name' => $name + ]); + } StatusHashtag::firstOrCreate([ 'status_id' => $status->id, From 6e20d0a6709c67b6b43475f4c22676ec6c5c6db5 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 May 2023 23:33:06 -0600 Subject: [PATCH 5/7] Update SearchApiV2Service, fix postgres hashtag search and prepend wildcard operator to improve results --- app/Services/SearchApiV2Service.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Services/SearchApiV2Service.php b/app/Services/SearchApiV2Service.php index a6826b77e..93a29cae9 100644 --- a/app/Services/SearchApiV2Service.php +++ b/app/Services/SearchApiV2Service.php @@ -125,8 +125,10 @@ class SearchApiV2Service $q = $this->query->input('q'); $limit = $this->query->input('limit') ?? 20; $offset = $this->query->input('offset') ?? 0; - $query = Str::startsWith($q, '#') ? substr($q, 1) . '%' : $q . '%'; - return Hashtag::where('name', 'like', $query) + $query = Str::startsWith($q, '#') ? '%' . substr($q, 1) . '%' : '%' . $q . '%'; + $operator = config('database.default') === 'pgsql' ? 'ilike' : 'like'; + return Hashtag::where('name', $operator, $query) + ->orWhere('slug', $operator, $query) ->where(function($q) { return $q->where('can_search', true) ->orWhereNull('can_search'); From 64059cb47e74011476b091dad0ffc4294ee2eab0 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 May 2023 23:34:06 -0600 Subject: [PATCH 6/7] Add postgres migration to fix duplicate hashtags --- ...023_05_03_042219_fix_postgres_hashtags.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 database/migrations/2023_05_03_042219_fix_postgres_hashtags.php diff --git a/database/migrations/2023_05_03_042219_fix_postgres_hashtags.php b/database/migrations/2023_05_03_042219_fix_postgres_hashtags.php new file mode 100644 index 000000000..1d4b1e820 --- /dev/null +++ b/database/migrations/2023_05_03_042219_fix_postgres_hashtags.php @@ -0,0 +1,46 @@ +name)->orderBy('id')->get(); + if($dups->count() === 1) { + continue; + } + + $first = $dups->shift(); + $dups->each(function($dup) use($first) { + StatusHashtag::whereHashtagId($dup->id)->update(['hashtag_id' => $first->id]); + $dup->delete(); + }); + } + + Cache::clear(); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; From 96d4486abbfd6ef65d41abf24404c6ed081d3880 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 2 May 2023 23:34:52 -0600 Subject: [PATCH 7/7] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3f606f37..ceb5d101e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Fixes - Fixed `violates check constraint "statuses_visibility_check"` bug affecting postgres instances + various api endpoints ([79b6a17e](https://github.com/pixelfed/pixelfed/commit/79b6a17e)) +- Fixed duplicate hashtags on postgres ([64059cb4](https://github.com/pixelfed/pixelfed/commit/64059cb4)) ### Updates - Update ApiV1Controller, fix blocking remote accounts. Closes #4256 ([8e71e0c0](https://github.com/pixelfed/pixelfed/commit/8e71e0c0)) @@ -40,6 +41,9 @@ - Update ForgotPasswordController, add captcha support, improve security and a new redesigned view ([f6e7ff64](https://github.com/pixelfed/pixelfed/commit/f6e7ff64)) - Update ResetPasswordController, add captcha support, improve security and a new redesigned view ([0ab5b96a](https://github.com/pixelfed/pixelfed/commit/0ab5b96a)) - Update Inbox, remove handleCreateActivity logic that rejected posts from accounts without followers ([a93a3efd](https://github.com/pixelfed/pixelfed/commit/a93a3efd)) +- Update ApiV1Controller and DiscoverController, fix postgres hashtag search ([055aa6b3](https://github.com/pixelfed/pixelfed/commit/055aa6b3)) +- Update StatusTagsPipeline, deduplicate hashtags on postgres ([867cbc75](https://github.com/pixelfed/pixelfed/commit/867cbc75)) +- Update SearchApiV2Service, fix postgres hashtag search and prepend wildcard operator to improve results ([6e20d0a6](https://github.com/pixelfed/pixelfed/commit/6e20d0a6)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.5 (2023-03-25)](https://github.com/pixelfed/pixelfed/compare/v0.11.4...v0.11.5)