Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/Steinbeck-Lab/coconut
Browse files Browse the repository at this point in the history
…into development
  • Loading branch information
CS76 committed Jan 15, 2025
2 parents a9140c8 + d87ed63 commit 78e604c
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 40 deletions.
18 changes: 9 additions & 9 deletions app/Console/Commands/DashWidgetsRefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,49 @@ public function handle()
// Cache::flush();

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

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

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

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

Cache::rememberForever('stats.reports', function () {
Cache::flexible('stats.reports', [172800, 259200], 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::flexible('stats.molecules.non_stereo', [172800, 259200], 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::flexible('stats.molecules.stereo', [172800, 259200], 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::flexible('stats.molecules.parent', [172800, 259200], 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::flexible('stats.molecules', [172800, 259200], 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
5 changes: 4 additions & 1 deletion app/Filament/Dashboard/Resources/CitationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;

class CitationResource extends Resource
Expand Down Expand Up @@ -76,6 +77,8 @@ public static function getPages(): array

public static function getNavigationBadge(): ?string
{
return Cache::get('stats.citations');
return Cache::flexible('stats.citations', [172800, 259200], function () {
return DB::table('citations')->selectRaw('count(*)')->get()[0]->count;
});
}
}
5 changes: 4 additions & 1 deletion app/Filament/Dashboard/Resources/CollectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;

Expand Down Expand Up @@ -161,6 +162,8 @@ public static function getWidgets(): array

public static function getNavigationBadge(): ?string
{
return Cache::get('stats.collections');
return Cache::flexible('stats.collections', [172800, 259200], function () {
return DB::table('collections')->selectRaw('count(*)')->get()[0]->count;
});
}
}
5 changes: 4 additions & 1 deletion app/Filament/Dashboard/Resources/GeoLocationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;

class GeoLocationResource extends Resource
Expand Down Expand Up @@ -83,6 +84,8 @@ public static function getWidgets(): array

public static function getNavigationBadge(): ?string
{
return Cache::get('stats.geo_locations');
return Cache::flexible('stats.geo_locations', [172800, 259200], function () {
return DB::table('geo_locations')->selectRaw('count(*)')->get()[0]->count;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class GeoLocationStats extends BaseWidget
protected function getStats(): array
{
return [
Stat::make('Total Molecules', Cache::rememberForever('stats.geo_locations'.$this->record->id.'molecules.count', function () {
Stat::make('Total Molecules', Cache::flexible('stats.geo_locations'.$this->record->id.'molecules.count', [172800, 259200], 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 () {
Stat::make('Total Organisms', Cache::flexible('stats.geo_locations'.$this->record->id.'organisms.count', [172800, 259200], 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;
})),
];
Expand Down
6 changes: 4 additions & 2 deletions app/Filament/Dashboard/Resources/MoleculeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use App\Filament\Dashboard\Resources\MoleculeResource\Widgets\MoleculeStats;
use App\Models\Molecule;
use Archilex\AdvancedTables\Filters\AdvancedFilter;
use DB;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
Expand All @@ -30,6 +29,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\HtmlString;
use pxlrbt\FilamentExcel\Actions\Tables\ExportBulkAction;
Expand Down Expand Up @@ -249,7 +249,9 @@ public static function getWidgets(): array

public static function getNavigationBadge(): ?string
{
return Cache::get('stats.molecules');
return Cache::flexible('stats.molecules', [172800, 259200], function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('active=true and NOT (is_parent=true AND has_variants=true)')->get()[0]->count;
});
}

public static function changeMoleculeStatus($record, $reason)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class MoleculeStats extends BaseWidget
protected function getStats(): array
{
return [
Stat::make('Total Organisms', Cache::remember('stats.molecules'.$this->record->id.'organisms.count', 172800, function () {
Stat::make('Total Organisms', Cache::flexible('stats.molecules'.$this->record->id.'organisms.count', [172800, 259200], function () {
return DB::table('molecule_organism')->selectRaw('count(*)')->whereRaw('molecule_id='.$this->record->id)->get()[0]->count;
})),
Stat::make('Total Geo Locations', Cache::remember('stats.molecules'.$this->record->id.'geo_locations.count', 172800, function () {
Stat::make('Total Geo Locations', Cache::flexible('stats.molecules'.$this->record->id.'geo_locations.count', [172800, 259200], function () {
return DB::table('geo_location_molecule')->selectRaw('count(*)')->whereRaw('molecule_id='.$this->record->id)->get()[0]->count;
})),
];
Expand Down
5 changes: 4 additions & 1 deletion app/Filament/Dashboard/Resources/OrganismResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use GuzzleHttp\Client;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Log;
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;

Expand Down Expand Up @@ -130,7 +131,9 @@ public static function getWidgets(): array

public static function getNavigationBadge(): ?string
{
return Cache::get('stats.organisms');
return Cache::flexible('stats.organisms', [172800, 259200], function () {
return DB::table('organisms')->selectRaw('count(*)')->get()[0]->count;
});
}

protected static function getGNFMatches($name, $organism)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class OrganismStats extends BaseWidget
protected function getStats(): array
{
return [
Stat::make('Total Molecules', Cache::remember('stats.organisms'.$this->record->id.'molecules.count', 172800, function () {
Stat::make('Total Molecules', Cache::flexible('stats.organisms'.$this->record->id.'molecules.count', [172800, 259200], function () {
return DB::table('molecule_organism')->selectRaw('count(*)')->whereRaw('organism_id='.$this->record->id)->get()[0]->count;
})),
Stat::make('Total Geo Locations', Cache::remember('stats.organisms'.$this->record->id.'geo_locations.count', 172800, function () {
Stat::make('Total Geo Locations', Cache::flexible('stats.organisms'.$this->record->id.'geo_locations.count', [172800, 259200], 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;
})),
];
Expand Down
21 changes: 16 additions & 5 deletions app/Filament/Dashboard/Widgets/DashboardStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class DashboardStats extends BaseWidget
{
Expand All @@ -18,12 +19,22 @@ public function getColumns(): int
protected function getStats(): array
{
return [
Stat::make('Total Collections', Cache::get('stats.collections')),
Stat::make('Total Citations', Cache::get('stats.citations')),
Stat::make('Total Collections', Cache::flexible('stats.collections', [172800, 259200], function () {
return DB::table('collections')->selectRaw('count(*)')->get()[0]->count;
})),
Stat::make('Total Citations', Cache::flexible('stats.citations', [172800, 259200], function () {
return DB::table('citations')->selectRaw('count(*)')->get()[0]->count;
})),

Stat::make('Total Organisms', Cache::get('stats.organisms')),
Stat::make('Total Geo Locations', Cache::get('stats.geo_locations')),
Stat::make('Total Reports', Cache::get('stats.reports')),
Stat::make('Total Organisms', Cache::flexible('stats.organisms', [172800, 259200], function () {
return DB::table('organisms')->selectRaw('count(*)')->get()[0]->count;
})),
Stat::make('Total Geo Locations', Cache::flexible('stats.geo_locations', [172800, 259200], function () {
return DB::table('geo_locations')->selectRaw('count(*)')->get()[0]->count;
})),
Stat::make('Total Reports', Cache::flexible('stats.reports', [172800, 259200], function () {
return DB::table('reports')->selectRaw('count(*)')->get()[0]->count;
})),
];
}
}
17 changes: 13 additions & 4 deletions app/Filament/Dashboard/Widgets/DashboardStatsMid.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class DashboardStatsMid extends BaseWidget
{
Expand All @@ -15,11 +16,19 @@ class DashboardStatsMid extends BaseWidget
protected function getStats(): array
{
return [
Stat::make('Total Molecules', Cache::get('stats.molecules')),
Stat::make('Total Non-Stereo Molecules', Cache::get('stats.molecules.non_stereo')),
Stat::make('Total Stereo Molecules', Cache::get('stats.molecules.stereo'))
Stat::make('Total Molecules', Cache::flexible('stats.molecules', [172800, 259200], function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('active=true and NOT (is_parent=true AND has_variants=true)')->get()[0]->count;
})),
Stat::make('Total Non-Stereo Molecules', Cache::flexible('stats.molecules.non_stereo', [172800, 259200], function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=false and is_parent=false')->get()[0]->count;
})),
Stat::make('Total Stereo Molecules', Cache::flexible('stats.molecules.stereo', [172800, 259200], function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=true')->get()[0]->count;
}))
->description(
'Total parent molecules: '.Cache::get('stats.molecules.parent')
'Total parent molecules: '.Cache::flexible('stats.molecules.parent', [172800, 259200], function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('has_stereo=false and is_parent=true')->get()[0]->count;
})
)
->color('primary'),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MolecularEntityController extends Controller
{
public function moleculeSchema(Request $request, $identifier)
{
$molecule = Cache::remember('molecules.'.$identifier, 172800, function () use ($identifier) {
$molecule = Cache::flexible('molecules.'.$identifier, [172800, 259200], function () use ($identifier) {
return Molecule::where('identifier', $identifier)->first();
});

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __invoke(Request $request, $id)
abort(404);
}

$collection = Cache::remember('collections.'.$id, 172800, function () use ($id) {
$collection = Cache::flexible('collections.'.$id, [172800, 259200], function () use ($id) {
return Collection::where('identifier', $id)->first();
});

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/MoleculeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __invoke(Request $request, $id)
$id .= '.0';
}

$molecule = Cache::remember('molecules.'.$id, 172800, function () use ($id) {
$molecule = Cache::flexible('molecules.'.$id, [172800, 259200], function () use ($id) {
return Molecule::where('identifier', $id)->first();
});

Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/DataSources.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DataSources extends Component

public function mount()
{
$this->collections = Cache::remember('collections', 172800, function () {
$this->collections = Cache::flexible('collections', [172800, 259200], function () {
return Collection::where('promote', true)->orderBy('sort_order')->take(10)->get(['title', 'image'])->toArray();
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/MoleculeDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function rendered()
$_molecule = Cache::get('molecules.'.$id);
if ($_molecule && ! $_molecule->relationLoaded('properties')) {
Cache::forget('molecules.'.$id);
Cache::remember('molecules.'.$id, 172800, function () use ($molecule) {
Cache::flexible('molecules.'.$id, [172800, 259200], function () use ($molecule) {
$molecule['schema'] = $molecule->getSchema();

return $molecule;
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/RecentMolecules.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class RecentMolecules extends Component
public function render()
{
return view('livewire.recent-molecules', [
'molecules' => Cache::remember('molecules.recent', 172800, function () {
'molecules' => Cache::flexible('molecules.recent', [172800, 259200], function () {
return Molecule::where('is_parent', false)->where('active', true)->where('name', '!=', null)->where('annotation_level', '=', 5)->orderByDesc('updated_at')->paginate($this->size);
}),
]);
Expand Down
17 changes: 13 additions & 4 deletions app/Livewire/Welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Livewire;

use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Livewire\Attributes\Lazy;
use Livewire\Attributes\Url;
use Livewire\Component;
Expand Down Expand Up @@ -51,10 +52,18 @@ public function placeholder()

public function render()
{
$this->totalMolecules = Cache::get('stats.molecules');
$this->totalCollections = Cache::get('stats.collections', 0);
$this->uniqueOrganisms = Cache::get('stats.organisms', 0);
$this->citationsMapped = Cache::get('stats.citations', 0);
$this->totalMolecules = Cache::flexible('stats.molecules', [172800, 259200], function () {
return DB::table('molecules')->selectRaw('count(*)')->whereRaw('active=true and NOT (is_parent=true AND has_variants=true)')->get()[0]->count;
});
$this->totalCollections = Cache::flexible('stats.collections', [172800, 259200], function () {
return DB::table('collections')->selectRaw('count(*)')->get()[0]->count;
});
$this->uniqueOrganisms = Cache::flexible('stats.organisms', [172800, 259200], function () {
return DB::table('organisms')->selectRaw('count(*)')->get()[0]->count;
});
$this->citationsMapped = Cache::flexible('stats.citations', [172800, 259200], function () {
return DB::table('citations')->selectRaw('count(*)')->get()[0]->count;
});

return view('livewire.welcome', [
'totalMolecules' => $this->totalMolecules,
Expand Down

0 comments on commit 78e604c

Please sign in to comment.