From 9b038b7b2d6e14062dddca30249620e9c88cb736 Mon Sep 17 00:00:00 2001 From: Dan Harrin Date: Mon, 30 Dec 2024 11:51:31 +0000 Subject: [PATCH] Count null IP checks --- app/Actions/GetPluginsListData.php | 2 +- app/Http/Controllers/Articles/ListArticlesController.php | 3 ++- app/Http/Controllers/Plugins/ListPluginsController.php | 3 ++- app/Models/Article.php | 2 +- app/Models/Author.php | 2 +- app/Models/Plugin.php | 3 ++- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Actions/GetPluginsListData.php b/app/Actions/GetPluginsListData.php index 76f654ddf..aa5c04c9b 100644 --- a/app/Actions/GetPluginsListData.php +++ b/app/Actions/GetPluginsListData.php @@ -22,7 +22,7 @@ function () use ($plugins): array { fn (Builder $query) => $query->whereIn('starrable_id', $plugins), ) ->where('starrable_type', 'plugin') - ->whereNot('is_vpn_ip', true) + ->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false)) ->groupBy('starrable_id') ->selectRaw('count(id) as count, starrable_id') ->get() diff --git a/app/Http/Controllers/Articles/ListArticlesController.php b/app/Http/Controllers/Articles/ListArticlesController.php index 1570a8b03..ae9c00824 100644 --- a/app/Http/Controllers/Articles/ListArticlesController.php +++ b/app/Http/Controllers/Articles/ListArticlesController.php @@ -8,6 +8,7 @@ use App\Models\ArticleType; use App\Models\Author; use App\Models\Star; +use Illuminate\Database\Query\Builder; class ListArticlesController extends Controller { @@ -31,7 +32,7 @@ function (): array { $stars = Star::query() ->toBase() ->where('starrable_type', 'article') - ->whereNot('is_vpn_ip', true) + ->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false)) ->groupBy('starrable_id') ->selectRaw('count(id) as count, starrable_id') ->get() diff --git a/app/Http/Controllers/Plugins/ListPluginsController.php b/app/Http/Controllers/Plugins/ListPluginsController.php index fb24d8e26..33ea43cf5 100644 --- a/app/Http/Controllers/Plugins/ListPluginsController.php +++ b/app/Http/Controllers/Plugins/ListPluginsController.php @@ -8,6 +8,7 @@ use App\Models\Plugin; use App\Models\PluginCategory; use App\Models\Star; +use Illuminate\Database\Eloquent\Builder; class ListPluginsController extends Controller { @@ -40,7 +41,7 @@ public function __invoke(GetPluginsListData $getPluginsListData) ]), 'starsCount' => Star::query() ->where('starrable_type', 'plugin') - ->whereNot('is_vpn_ip', true) + ->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false)) ->count(), ]); } diff --git a/app/Models/Article.php b/app/Models/Article.php index b19088aa3..89df6782a 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -64,7 +64,7 @@ public function getStarsCount(): int return cache()->remember( $this->getStarsCountCacheKey(), now()->addDay(), - fn (): int => $this->stars()->whereNot('is_vpn_ip', true)->count(), + fn (): int => $this->stars()->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false))->count(), ); } diff --git a/app/Models/Author.php b/app/Models/Author.php index 118504f9f..21f784c6b 100644 --- a/app/Models/Author.php +++ b/app/Models/Author.php @@ -58,7 +58,7 @@ public function getStarsCount(): int $this->getStarsCountCacheKey(), now()->addDay(), fn (): int => Star::query() - ->whereNot('is_vpn_ip', true) + ->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false)) ->where(fn (Builder $query) => $query->where('starrable_type', 'article')->whereIn('starrable_id', $this->articles()->pluck('slug'))) ->orWhere(fn (Builder $query) => $query->where('starrable_type', 'plugin')->whereIn('starrable_id', $this->plugins()->pluck('slug'))) ->count(), diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index 6a579a7b6..a86b5dfca 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Models\Contracts\Starrable; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -129,7 +130,7 @@ public function getStarsCount(): int return cache()->remember( $this->getStarsCountCacheKey(), now()->addDay(), - fn (): int => $this->stars()->whereNot('is_vpn_ip', true)->count(), + fn (): int => $this->stars()->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false))->count(), ); }