Increase speed of processing the prices and products. Because this is getting out of hand.

This commit was merged in pull request #33.
This commit is contained in:
2026-01-08 17:18:46 +01:00
parent de4915972c
commit 8e8ef8fe04
7 changed files with 67 additions and 15 deletions

View File

@@ -20,6 +20,10 @@ use function Symfony\Component\Clock\now;
* @property string $modelCode
* @property string $url
* @property int $starred
* @property float $priceCurrent
* @property float $priceLowest
* @property float $productStandardPrice
* @property float $lowestProductPrice30Days
*/
class Product extends Model
{
@@ -45,6 +49,10 @@ class Product extends Model
{
return $this->hasOne(Price::class)->ofMany('price', 'MIN');
}
public function newestPrice(): HasOne
{
return $this->hasOne(Price::class)->latest();
}
public function stock(): HasMany
{
@@ -53,9 +61,7 @@ class Product extends Model
public function currentStock(): HasOne
{
return $this->stock()->one()->ofMany()->withDefault(function (Stock $stock) {
$stock->stock = 0;
});
return $this->stock()->one()->ofMany()->withDefault(fn (Stock $stock) => $stock->stock = 0);
}
public function toggleStarred(): self