From 847137f66890607d1d85addc63c3f7b045c99da0 Mon Sep 17 00:00:00 2001 From: Sagar Date: Tue, 10 Sep 2024 10:16:49 +0200 Subject: [PATCH] fix: all the values caches are set to expire after 2 days. --- app/Console/Commands/DashWidgetsRefresh.php | 18 +++++++++--------- .../Widgets/CollectionStats.php | 2 +- .../MoleculeResource/Widgets/MoleculeStats.php | 4 ++-- .../OrganismResource/Widgets/OrganismStats.php | 4 ++-- .../Bioschemas/MolecularEntityController.php | 2 +- app/Http/Controllers/MoleculeController.php | 2 +- app/Livewire/DataSources.php | 2 +- app/Livewire/MoleculeDetails.php | 2 +- app/Livewire/RecentMolecules.php | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/Console/Commands/DashWidgetsRefresh.php b/app/Console/Commands/DashWidgetsRefresh.php index d8e4a823..1dfdf142 100644 --- a/app/Console/Commands/DashWidgetsRefresh.php +++ b/app/Console/Commands/DashWidgetsRefresh.php @@ -32,49 +32,49 @@ public function handle() // Cache::flush(); // Create the cache for all DashboardStats widgets - Cache::rememberForever('stats.collections', function () { + Cache::remember('stats.collections', 172800, function () { return DB::table('collections')->selectRaw('count(*)')->get()[0]->count; }); $this->info('Cache for collections refreshed.'); - Cache::rememberForever('stats.citations', function () { + Cache::remember('stats.citations', 172800, function () { return DB::table('citations')->selectRaw('count(*)')->get()[0]->count; }); $this->info('Cache for citations refreshed.'); - Cache::rememberForever('stats.organisms', function () { + Cache::remember('stats.organisms', 172800, function () { return DB::table('organisms')->selectRaw('count(*)')->get()[0]->count; }); $this->info('Cache for organisms refreshed.'); - Cache::rememberForever('stats.geo_locations', function () { + Cache::remember('stats.geo_locations', 172800, function () { return DB::table('geo_locations')->selectRaw('count(*)')->get()[0]->count; }); $this->info('Cache for geo locations refreshed.'); - Cache::rememberForever('stats.reports', function () { + Cache::remember('stats.reports', 172800, function () { return DB::table('reports')->selectRaw('count(*)')->get()[0]->count; }); $this->info('Cache for reports refreshed.'); // Create the cache for all DashboardStatsMid widgets - Cache::rememberForever('stats.molecules.non_stereo', function () { + Cache::remember('stats.molecules.non_stereo', 172800, function () { return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=false and is_parent=false')->get()[0]->count; }); $this->info('Cache for molecules non-stereo refreshed.'); - Cache::rememberForever('stats.molecules.stereo', function () { + Cache::remember('stats.molecules.stereo', 172800, function () { return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=true')->get()[0]->count; }); $this->info('Cache for molecules stereo refreshed.'); - Cache::rememberForever('stats.molecules.parent', function () { + Cache::remember('stats.molecules.parent', 172800, function () { return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=false and is_parent=true')->get()[0]->count; }); $this->info('Cache for molecules parent refreshed.'); - Cache::rememberForever('stats.molecules', function () { + Cache::remember('stats.molecules', 172800, function () { return DB::table('molecules')->selectRaw('count(*)')->whereRaw('active=true and NOT (is_parent=true AND has_variants=true)')->get()[0]->count; }); $this->info('Cache for molecules refreshed.'); diff --git a/app/Filament/Dashboard/Resources/CollectionResource/Widgets/CollectionStats.php b/app/Filament/Dashboard/Resources/CollectionResource/Widgets/CollectionStats.php index 64684ab5..724d161e 100644 --- a/app/Filament/Dashboard/Resources/CollectionResource/Widgets/CollectionStats.php +++ b/app/Filament/Dashboard/Resources/CollectionResource/Widgets/CollectionStats.php @@ -17,7 +17,7 @@ protected function getStats(): array return [ // Commented is the model query that we can use in case we decide not to use app level caching as the app scales up. - // Stat::make('Entries', Cache::rememberForever('stats.collections'.$this->record->id.'entries.count', function () { + // Stat::make('Entries', Cache::remember('stats.collections'.$this->record->id.'entries.count', 172800, function () { // return DB::table('entries')->selectRaw('count(*)')->whereRaw('collection_id='.$this->record->id)->get()[0]->count; // })) // ->description('Total count') diff --git a/app/Filament/Dashboard/Resources/MoleculeResource/Widgets/MoleculeStats.php b/app/Filament/Dashboard/Resources/MoleculeResource/Widgets/MoleculeStats.php index 8e594195..ce6fec7f 100644 --- a/app/Filament/Dashboard/Resources/MoleculeResource/Widgets/MoleculeStats.php +++ b/app/Filament/Dashboard/Resources/MoleculeResource/Widgets/MoleculeStats.php @@ -15,10 +15,10 @@ class MoleculeStats extends BaseWidget protected function getStats(): array { return [ - Stat::make('Total Organisms', Cache::rememberForever('stats.molecules'.$this->record->id.'organisms.count', function () { + Stat::make('Total Organisms', Cache::remember('stats.molecules'.$this->record->id.'organisms.count', 172800, function () { return DB::table('molecule_organism')->selectRaw('count(*)')->whereRaw('molecule_id='.$this->record->id)->get()[0]->count; })), - Stat::make('Total Geo Locations', Cache::rememberForever('stats.molecules'.$this->record->id.'geo_locations.count', function () { + Stat::make('Total Geo Locations', Cache::remember('stats.molecules'.$this->record->id.'geo_locations.count', 172800, function () { return DB::table('geo_location_molecule')->selectRaw('count(*)')->whereRaw('molecule_id='.$this->record->id)->get()[0]->count; })), ]; diff --git a/app/Filament/Dashboard/Resources/OrganismResource/Widgets/OrganismStats.php b/app/Filament/Dashboard/Resources/OrganismResource/Widgets/OrganismStats.php index 1a31d6f0..25577082 100644 --- a/app/Filament/Dashboard/Resources/OrganismResource/Widgets/OrganismStats.php +++ b/app/Filament/Dashboard/Resources/OrganismResource/Widgets/OrganismStats.php @@ -15,10 +15,10 @@ class OrganismStats extends BaseWidget protected function getStats(): array { return [ - Stat::make('Total Molecules', Cache::rememberForever('stats.organisms'.$this->record->id.'molecules.count', function () { + Stat::make('Total Molecules', Cache::remember('stats.organisms'.$this->record->id.'molecules.count', 172800, function () { return DB::table('molecule_organism')->selectRaw('count(*)')->whereRaw('organism_id='.$this->record->id)->get()[0]->count; })), - Stat::make('Total Geo Locations', Cache::rememberForever('stats.organisms'.$this->record->id.'geo_locations.count', function () { + Stat::make('Total Geo Locations', Cache::remember('stats.organisms'.$this->record->id.'geo_locations.count', 172800, function () { return DB::table('molecule_organism')->selectRaw('count(*)')->whereRaw('organism_id='.$this->record->id)->Join('geo_location_molecule', 'molecule_organism.molecule_id', '=', 'geo_location_molecule.molecule_id')->get()[0]->count; })), ]; diff --git a/app/Http/Controllers/API/Schemas/Bioschemas/MolecularEntityController.php b/app/Http/Controllers/API/Schemas/Bioschemas/MolecularEntityController.php index 02ee546c..2152462d 100644 --- a/app/Http/Controllers/API/Schemas/Bioschemas/MolecularEntityController.php +++ b/app/Http/Controllers/API/Schemas/Bioschemas/MolecularEntityController.php @@ -15,7 +15,7 @@ class MolecularEntityController extends Controller { public function moleculeSchema(Request $request, $identifier) { - $molecule = Cache::rememberForever('molecules.'.$identifier, function () use ($identifier) { + $molecule = Cache::remember('molecules.'.$identifier, 172800, function () use ($identifier) { return Molecule::where('identifier', $identifier)->first(); }); diff --git a/app/Http/Controllers/MoleculeController.php b/app/Http/Controllers/MoleculeController.php index 41c45598..040cab23 100644 --- a/app/Http/Controllers/MoleculeController.php +++ b/app/Http/Controllers/MoleculeController.php @@ -17,7 +17,7 @@ public function __invoke(Request $request, $id) $id .= '.0'; } - $molecule = Cache::rememberForever('molecules.'.$id, function () use ($id) { + $molecule = Cache::remember('molecules.'.$id, 172800, function () use ($id) { return Molecule::where('identifier', $id)->first(); }); diff --git a/app/Livewire/DataSources.php b/app/Livewire/DataSources.php index 7158b541..f1367766 100644 --- a/app/Livewire/DataSources.php +++ b/app/Livewire/DataSources.php @@ -12,7 +12,7 @@ class DataSources extends Component public function mount() { - $this->collections = Cache::rememberForever('collections', function () { + $this->collections = Cache::remember('collections', 172800, function () { return Collection::where('promote', true)->orderBy('sort_order')->take(10)->get(['title', 'image'])->toArray(); }); } diff --git a/app/Livewire/MoleculeDetails.php b/app/Livewire/MoleculeDetails.php index 67fa86a0..4c68b249 100644 --- a/app/Livewire/MoleculeDetails.php +++ b/app/Livewire/MoleculeDetails.php @@ -24,7 +24,7 @@ public function rendered() $_molecule = Cache::get('molecules.'.$id); if (! $_molecule->relationLoaded('properties')) { Cache::forget('molecules.'.$id); - Cache::rememberForever('molecules.'.$id, function () use ($molecule) { + Cache::remember('molecules.'.$id, 172800, function () use ($molecule) { $molecule['schema'] = $molecule->getSchema(); return $molecule; diff --git a/app/Livewire/RecentMolecules.php b/app/Livewire/RecentMolecules.php index 845443ff..0da5ad41 100644 --- a/app/Livewire/RecentMolecules.php +++ b/app/Livewire/RecentMolecules.php @@ -16,7 +16,7 @@ class RecentMolecules extends Component public function render() { return view('livewire.recent-molecules', [ - 'molecules' => Cache::rememberForever('molecules.recent', function () { + 'molecules' => Cache::remember('molecules.recent', 172800, function () { return Molecule::where('is_parent', false)->where('active', true)->where('name', '!=', null)->where('annotation_level', '=', 5)->orderByDesc('updated_at')->paginate($this->size); }), ]);