diff --git a/CHANGELOG.md b/CHANGELOG.md index 988bb6448..ceb5d101e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,13 @@ - 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)) +- 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)) - Update ComposeController, fix postgres location search. Closes #4242 and #4239 ([64a4a006](https://github.com/pixelfed/pixelfed/commit/64a4a006)) @@ -37,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) 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 []; } 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, 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'); 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), ], ], 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 + { + // + } +};