Skip to content

Commit

Permalink
Count null IP checks
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Dec 30, 2024
1 parent 823d901 commit 9b038b7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Actions/GetPluginsListData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Articles/ListArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Plugins/ListPluginsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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(),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Models/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
);
}

Expand Down

0 comments on commit 9b038b7

Please sign in to comment.