Skip to content

Commit

Permalink
fix: cache
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Nov 24, 2024
1 parent c688e4a commit fa4b4d4
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions app/Livewire/Pages/ElectionResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace App\Livewire\Pages;

use App\Enums\Time;
use App\Models\Candidate;
use App\Models\Party;
use App\Models\Vote;
use App\Repositories\RecordsRepository;
use App\Repositories\VotesRepository;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Number;
use Illuminate\View\View;
use Livewire\Attributes\Computed;
Expand All @@ -29,28 +31,32 @@ public function render(): View
return view('livewire.pages.election-results');
}

#[Computed(cache: true)]
#[Computed]
public function parties(): Collection
{
return Party::query()
->whereBelongsTo($this->election)
// ->whereHas('votes', function (Builder $query) {
return Cache::remember("parties:{$this->election->id}", Time::DAY_IN_SECONDS->value, function () {
return Party::query()
->whereBelongsTo($this->election)
// ->whereHas('votes', function (Builder $query) {
// $query->whereBelongsTo($this->election);
// })
->with('media')
->get();
// })
->with('media')
->get();
});
}

#[Computed(cache: true)]
#[Computed]
public function candidates(): Collection
{
return Candidate::query()
->whereBelongsTo($this->election)
// ->whereHas('votes', function (Builder $query) {
return Cache::remember("candidates:{$this->election->id}", Time::DAY_IN_SECONDS->value, function () {
return Candidate::query()
->whereBelongsTo($this->election)
// ->whereHas('votes', function (Builder $query) {
// $query->whereBelongsTo($this->election);
// })
->with('media')
->get();
// })
->with('media')
->get();
});
}

#[Computed]
Expand Down

0 comments on commit fa4b4d4

Please sign in to comment.