Skip to content

Commit 9b038b7

Browse files
committed
Count null IP checks
1 parent 823d901 commit 9b038b7

File tree

6 files changed

+9
-6
lines changed

6 files changed

+9
-6
lines changed

app/Actions/GetPluginsListData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function () use ($plugins): array {
2222
fn (Builder $query) => $query->whereIn('starrable_id', $plugins),
2323
)
2424
->where('starrable_type', 'plugin')
25-
->whereNot('is_vpn_ip', true)
25+
->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false))
2626
->groupBy('starrable_id')
2727
->selectRaw('count(id) as count, starrable_id')
2828
->get()

app/Http/Controllers/Articles/ListArticlesController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Models\ArticleType;
99
use App\Models\Author;
1010
use App\Models\Star;
11+
use Illuminate\Database\Query\Builder;
1112

1213
class ListArticlesController extends Controller
1314
{
@@ -31,7 +32,7 @@ function (): array {
3132
$stars = Star::query()
3233
->toBase()
3334
->where('starrable_type', 'article')
34-
->whereNot('is_vpn_ip', true)
35+
->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false))
3536
->groupBy('starrable_id')
3637
->selectRaw('count(id) as count, starrable_id')
3738
->get()

app/Http/Controllers/Plugins/ListPluginsController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Models\Plugin;
99
use App\Models\PluginCategory;
1010
use App\Models\Star;
11+
use Illuminate\Database\Eloquent\Builder;
1112

1213
class ListPluginsController extends Controller
1314
{
@@ -40,7 +41,7 @@ public function __invoke(GetPluginsListData $getPluginsListData)
4041
]),
4142
'starsCount' => Star::query()
4243
->where('starrable_type', 'plugin')
43-
->whereNot('is_vpn_ip', true)
44+
->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false))
4445
->count(),
4546
]);
4647
}

app/Models/Article.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function getStarsCount(): int
6464
return cache()->remember(
6565
$this->getStarsCountCacheKey(),
6666
now()->addDay(),
67-
fn (): int => $this->stars()->whereNot('is_vpn_ip', true)->count(),
67+
fn (): int => $this->stars()->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false))->count(),
6868
);
6969
}
7070

app/Models/Author.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getStarsCount(): int
5858
$this->getStarsCountCacheKey(),
5959
now()->addDay(),
6060
fn (): int => Star::query()
61-
->whereNot('is_vpn_ip', true)
61+
->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false))
6262
->where(fn (Builder $query) => $query->where('starrable_type', 'article')->whereIn('starrable_id', $this->articles()->pluck('slug')))
6363
->orWhere(fn (Builder $query) => $query->where('starrable_type', 'plugin')->whereIn('starrable_id', $this->plugins()->pluck('slug')))
6464
->count(),

app/Models/Plugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Models;
44

55
use App\Models\Contracts\Starrable;
6+
use Illuminate\Database\Eloquent\Builder;
67
use Illuminate\Database\Eloquent\Collection;
78
use Illuminate\Database\Eloquent\Model;
89
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -129,7 +130,7 @@ public function getStarsCount(): int
129130
return cache()->remember(
130131
$this->getStarsCountCacheKey(),
131132
now()->addDay(),
132-
fn (): int => $this->stars()->whereNot('is_vpn_ip', true)->count(),
133+
fn (): int => $this->stars()->where(fn (Builder $query) => $query->whereNull('is_vpn_ip')->orWhere('is_vpn_ip', false))->count(),
133134
);
134135
}
135136

0 commit comments

Comments
 (0)