Skip to content

Commit

Permalink
feat: enabled cache and various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed May 29, 2024
1 parent b2697dc commit 97f9acb
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 22 deletions.
8 changes: 4 additions & 4 deletions app/Console/Commands/ImportClassyFire.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Log;
use App\Models\Properties;
use DB;
use Illuminate\Console\Command;
use Log;

class ImportClassyFire extends Command
{
Expand Down Expand Up @@ -36,7 +36,7 @@ public function handle()
return 1;
}

Log::info("Reading file: " . $file);
Log::info('Reading file: '.$file);

$batchSize = 10000;
$header = null;
Expand Down Expand Up @@ -85,7 +85,7 @@ private function insertBatch(array $data)
foreach ($data as $row) {
Properties::updateorCreate(
[
'molecule_id' => $row['id']
'molecule_id' => $row['id'],
],
[
'chemical_class' => str_replace('"', '', $row['chemical_class']),
Expand Down
10 changes: 5 additions & 5 deletions app/Console/Commands/ImportProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Log;
use App\Models\Properties;
use DB;
use Illuminate\Console\Command;
use Log;

class ImportProperties extends Command
{
Expand Down Expand Up @@ -36,7 +36,7 @@ public function handle()
return 1;
}

Log::info("Reading file: " . $file);
Log::info('Reading file: '.$file);

$batchSize = 10000;
$header = null;
Expand Down Expand Up @@ -85,7 +85,7 @@ private function insertBatch(array $data)
foreach ($data as $row) {
Properties::updateorCreate(
[
'molecule_id' => $row['id']
'molecule_id' => $row['id'],
],
[
'total_atom_count' => str_replace('"', '', $row['atom_count']),
Expand All @@ -110,7 +110,7 @@ private function insertBatch(array $data)
'contains_ring_sugars' => str_replace('"', '', $row['circular_sugars']),
'contains_sugar' => filter_var(str_replace('"', '', $row['linear_sugars']), FILTER_VALIDATE_BOOLEAN) || filter_var(str_replace('"', '', $row['circular_sugars']), FILTER_VALIDATE_BOOLEAN),
'murko_framework' => str_replace('"', '', $row['murko_framework']),
'nplikeness' => str_replace('"', '', $row['nplikeness']),
'np_likeness' => str_replace('"', '', $row['nplikeness']),
'molecular_formula' => str_replace('"', '', $row['molecular_formula']),
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ protected function getStats(): array
$molecules = $this->record->molecules;
$count = 0;
foreach ($molecules as $molecule) {
$count += $molecule->geoLocations()->count();
$count += $molecule->geo_locations()->count();
}

return $count;
})),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class GeoLocationRelationManager extends RelationManager
{
protected static string $relationship = 'geoLocations';
protected static string $relationship = 'geo_locations';

public function form(Form $form): Form
{
Expand Down
4 changes: 2 additions & 2 deletions app/Livewire/DataSources.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
namespace App\Livewire;

use App\Models\Collection;
use Livewire\Component;
use Cache;
use Livewire\Component;

class DataSources extends Component
{
public $collections = [];

public function mount()
{
$this->collections = Cache::rememberForever('collections', function (){
$this->collections = Cache::rememberForever('collections', function () {
return Collection::limit(10)->pluck('title');
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/Livewire/MoleculeDepict2d.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MoleculeDepict2d extends Component
#[Computed]
public function source()
{
return env('CM_API').'depict/2D?smiles='.urlencode($this->smiles).'&height='.$this->height.'&width='.$this->width.'&CIP='.$this->CIP.'&toolkit=rdkit';
return env('CM_API').'depict/2D?smiles='.urlencode($this->smiles).'&height='.$this->height.'&width='.$this->width.'&toolkit=cdk';
}

public function render()
Expand Down
5 changes: 4 additions & 1 deletion app/Livewire/MoleculeDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Livewire;

use App\Models\Molecule;
use Cache;
use Livewire\Attributes\Layout;
use Livewire\Component;

Expand All @@ -12,7 +13,9 @@ class MoleculeDetails extends Component

public function mount($id)
{
$this->molecule = Molecule::with('properties', 'citations', 'collections', 'audits', 'variants')->where('identifier', $id)->first();
$this->molecule = Cache::remember('molecules.'.$id, 1440, function () use ($id) {
return Molecule::with('properties', 'citations', 'collections', 'audits', 'variants', 'organisms', 'geo_locations', 'related')->where('identifier', $id)->first();
});
}

#[Layout('layouts.guest')]
Expand Down
7 changes: 3 additions & 4 deletions app/Livewire/RecentMolecules.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use App\Http\Resources\MoleculeResource;
use App\Models\Molecule;
use Cache;
use Livewire\Component;
use Livewire\WithPagination;
use Cache;

class RecentMolecules extends Component
{
Expand All @@ -17,10 +17,9 @@ class RecentMolecules extends Component
public function render()
{
return view('livewire.recent-molecules', [
'molecules' =>
Cache::rememberForever('molecules.recent', function (){
'molecules' => Cache::rememberForever('molecules.recent', function () {
return MoleculeResource::collection(Molecule::where('has_variants', true)->where('name', '!=', null)->orderByDesc('updated_at')->paginate($this->size));
})
}),
]);
}
}
2 changes: 1 addition & 1 deletion app/Models/Molecule.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function organisms(): BelongsToMany
/**
* Get all of the geo-locations for the molecule.
*/
public function geoLocations(): BelongsToMany
public function geo_locations(): BelongsToMany
{
return $this->belongsToMany(GeoLocation::class)->withPivot('locations')->withTimestamps();
}
Expand Down
29 changes: 28 additions & 1 deletion resources/views/livewire/molecule-details.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,33 @@ class="flex items-baseline flex-wrap justify-between gap-y-2 gap-x-4 border-t bo
<div
class="mx-auto mt-8 grid max-w-3xl grid-cols-1 gap-6 sm:px-6 lg:max-w-7xl lg:grid-flow-col-dense lg:grid-cols-3">
<div class="space-y-6 lg:col-span-2 lg:col-start-1">
@if ($molecule->organisms && count($molecule->organisms) > 0)
<section>
<div class="bg-white border shadow sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
<h2 id="applicant-information-title" class="text-lg font-medium leading-6 text-gray-900">
Organisms</h2>
</div>
<div class="border-t border-gray-200">
<div class="no-scrollbar px-4 py-4 lg:px-8 min-w-0">
<ul role="list" class="mt-2 leading-8">
@foreach ($molecule->organisms as $organism)
@if ($organism != '')
<li class="inline">
<a class="text-sm relative mr-2 inline-flex items-center rounded-md border border-gray-300 px-3 py-0.5"
href="{{ urldecode($organism->iri) }}"
target="_blank">
{{ $organism->name }} | {{ $organism->rank }}
</a>
</li>
@endif
@endforeach
</ul>
</div>
</div>
</div>
</section>
@endif
<section>
<div class="bg-white border shadow sm:rounded-lg">
<div class="px-4 py-5 sm:px-6">
Expand Down Expand Up @@ -157,7 +184,7 @@ class="text-sm font-medium text-gray-500 sm:flex sm:justify-between">
<div class="group/item -ml-4 rounded-xl p-4 hover:bg-slate-100">
<dt
class="text-sm font-medium text-gray-500 sm:flex sm:justify-between">
Canonical SMILES (CDK)
Canonical SMILES (RDKit)
</dt>
<div class="mt-1 break-all text-sm text-gray-900">
{{ $molecule->canonical_smiles }}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/livewire/search.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class="rounded-md bg-white text-gray-900 mr-3 py-3 px-2 text-gray-400 hover:bg-g
<livewire:molecule-editor />
</div>
<div class="mx-auto max-w-2xl px-4 py-8 sm:px-6 sm:py-8 lg:max-w-7xl lg:px-8">
<div class="p-4">
<div class="p-4 w-full">
{{ $molecules->links() }}
</div>
<div class="grid grid-cols-1 gap-y-4 sm:grid-cols-2 sm:gap-x-6 sm:gap-y-10 lg:grid-cols-4 lg:gap-x-8">
Expand Down

0 comments on commit 97f9acb

Please sign in to comment.