Skip to content

Commit

Permalink
Merge pull request #23 from Steinbeck-Lab/functionality-schedule-dash…
Browse files Browse the repository at this point in the history
…-widgets

Functionality schedule dash widgets
  • Loading branch information
CS76 authored May 15, 2024
2 parents a608aca + c6a1489 commit e08e647
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
85 changes: 85 additions & 0 deletions app/Console/Commands/DashWidgetsRefresh.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Console\Commands;

use App\Models\Citation;
use App\Models\Collection;
use App\Models\GeoLocation;
use App\Models\Molecule;
use App\Models\Organism;
use App\Models\Report;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;

class DashWidgetsRefresh extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:dash-widgets-refresh';

/**
* The console command description.
*
* @var string
*/
protected $description = 'This refreshes the dashboard widgets.';

/**
* Execute the console command.
*/
public function handle()
{
// Clear the cache for all dashboard widgets
Cache::forget('stats.collections');
Cache::forget('stats.citations');
Cache::forget('stats.organisms');
Cache::forget('stats.geo_locations');
Cache::forget('stats.reports');
Cache::forget('stats.molecules');
Cache::forget('stats.molecules.non_stereo');
Cache::forget('stats.molecules.stereo');
Cache::forget('stats.molecules.parent');

// Create the cache for all DashboardStats widgets
Cache::rememberForever('stats.collections', function () {
return Collection::count();
});
Cache::rememberForever('stats.citations', function () {
return Citation::count();
});
Cache::rememberForever('stats.organisms', function () {
return Organism::count();
});
Cache::rememberForever('stats.geo_locations', function () {
return GeoLocation::count();
});
Cache::rememberForever('stats.reports', function () {
return Report::count();
});

// Create the cache for all DashboardStatsMid widgets
Cache::rememberForever('stats.molecules', function () {
return Molecule::count();
});
Cache::rememberForever('stats.molecules.non_stereo', function () {
return Molecule::where([
['has_stereo', false],
['is_parent', false],
])->count();
});
Cache::rememberForever('stats.molecules.stereo', function () {
return Molecule::where([
['has_stereo', true],
])->count();
});
Cache::rememberForever('stats.molecules.parent', function () {
return Molecule::where([
['has_stereo', false],
['is_parent', true],
])->count();
});
}
}
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protected function schedule(Schedule $schedule): void
// $schedule->command('inspire')->hourly();
$schedule->command('entries:process')->everyMinute()->withoutOverlapping();
$schedule->command('entries:import')->everyMinute()->withoutOverlapping();
$schedule->command('app:dash-widgets-refresh')->everyFifteenMinutes()->withoutOverlapping();
}

/**
Expand Down

0 comments on commit e08e647

Please sign in to comment.