Skip to content

Commit

Permalink
Performance optimizations (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
indykoning authored Oct 30, 2024
1 parent 170824b commit da67c9a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"php": "^8.1|^8.2",
"rapidez/blade-directives": "^0.6",
"justbetter/statamic-glide-directive": "^2.1",
"spatie/once": "*",
"statamic-rad-pack/runway": "^7.6",
"statamic/cms": "^5.0",
"statamic/eloquent-driver": "^4.9",
Expand Down
10 changes: 7 additions & 3 deletions src/Extend/SitesLinkedToMagentoStores.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

namespace Rapidez\Statamic\Extend;

use Illuminate\Support\Collection;
use Statamic\Sites\Sites;

class SitesLinkedToMagentoStores extends Sites
{
public function findByUrl($url)
{
if ($site = $this->findByMageRunCode(request()->server('MAGE_RUN_CODE'))) {
if ($site = once(fn() => $this->findByMageRunCode(request()->server('MAGE_RUN_CODE')))) {
return $site;
}

return parent::findByUrl($url);
return once(fn() => parent::findByUrl($url));
}


public function findByMageRunCode($code)
{
return collect($this->sites)->get($code);
if (!$code || !($this->sites instanceof Collection)) {
return null;
}
return $this->sites->get($code));
}
}
5 changes: 4 additions & 1 deletion src/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class Category extends Model

public function getTable()
{
return 'catalog_category_flat_store_'.(Statamic::isCpRoute() ? (Site::selected()->attributes['magento_store_id'] ?? '1') : (Site::current()->attributes['magento_store_id'] ?? '1'));
return 'catalog_category_flat_store_'.once(fn() => (Statamic::isCpRoute()
? (Site::selected()->attributes['magento_store_id'] ?? '1')
: (Site::current()->attributes['magento_store_id'] ?? '1')
));
}
}
5 changes: 4 additions & 1 deletion src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ protected static function booting()

public function getTable()
{
return 'catalog_product_flat_' . (Statamic::isCpRoute() ? (Site::selected()->attributes['magento_store_id'] ?? '1') : Site::current()->attributes['magento_store_id'] ?? '1');
return 'catalog_product_flat_' . once(fn() => (Statamic::isCpRoute()
? (Site::selected()->attributes['magento_store_id'] ?? '1')
: (Site::current()->attributes['magento_store_id'] ?? '1')
));
}
}

0 comments on commit da67c9a

Please sign in to comment.