Skip to content

Commit

Permalink
Merge pull request #262 from Steinbeck-Lab/fix-dashwidgets-autoflush-…
Browse files Browse the repository at this point in the history
…removal

fix: auto flush removed for dash widgets and geo-locations'
  • Loading branch information
CS76 authored Oct 9, 2024
2 parents 3af830d + 3ce816a commit 9345d1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
20 changes: 10 additions & 10 deletions app/Console/Commands/DashWidgetsRefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,52 @@ class DashWidgetsRefresh extends Command
public function handle()
{
// Clear the cache for all widgets
// Cache::flush();
Cache::flush();

// Create the cache for all DashboardStats widgets
Cache::remember('stats.collections', 172800, function () {
Cache::rememberForever('stats.collections', function () {
return DB::table('collections')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for collections refreshed.');

Cache::remember('stats.citations', 172800, function () {
Cache::rememberForever('stats.citations', function () {
return DB::table('citations')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for citations refreshed.');

Cache::remember('stats.organisms', 172800, function () {
Cache::rememberForever('stats.organisms', function () {
return DB::table('organisms')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for organisms refreshed.');

Cache::remember('stats.geo_locations', 172800, function () {
Cache::rememberForever('stats.geo_locations', function () {
return DB::table('geo_locations')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for geo locations refreshed.');

Cache::remember('stats.reports', 172800, function () {
Cache::rememberForever('stats.reports', function () {
return DB::table('reports')->selectRaw('count(*)')->get()[0]->count;
});
$this->info('Cache for reports refreshed.');

// Create the cache for all DashboardStatsMid widgets

Cache::remember('stats.molecules.non_stereo', 172800, function () {
Cache::rememberForever('stats.molecules.non_stereo', 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::remember('stats.molecules.stereo', 172800, function () {
Cache::rememberForever('stats.molecules.stereo', function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=true')->get()[0]->count;
});
$this->info('Cache for molecules stereo refreshed.');

Cache::remember('stats.molecules.parent', 172800, function () {
Cache::rememberForever('stats.molecules.parent', 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::remember('stats.molecules', 172800, function () {
Cache::rememberForever('stats.molecules', 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.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class GeoLocationStats extends BaseWidget
{
Expand All @@ -14,8 +15,12 @@ class GeoLocationStats extends BaseWidget
protected function getStats(): array
{
return [
Stat::make('Total Molecules', Cache::get('stats.geo_locations'.$this->record->id.'molecules.count')),
Stat::make('Total Organisms', Cache::get('stats.geo_locations'.$this->record->id.'organisms.count')),
Stat::make('Total Molecules', Cache::rememberForever('stats.geo_locations'.$this->record->id.'molecules.count', function () {
return DB::table('geo_location_molecule')->selectRaw('count(*)')->whereRaw('geo_location_id='.$this->record->id)->get()[0]->count;
})),
Stat::make('Total Organisms', Cache::rememberForever('stats.geo_locations'.$this->record->id.'organisms.count', function () {
return DB::table('geo_location_molecule')->selectRaw('count(*)')->whereRaw('geo_location_id='.$this->record->id)->Join('molecule_organism', 'geo_location_molecule.molecule_id', '=', 'molecule_organism.molecule_id')->get()[0]->count;
})),
];
}
}

0 comments on commit 9345d1d

Please sign in to comment.