Studio: make grid checkbox rectangular and commit table changes
This commit is contained in:
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Jobs\RecComputeSimilarByBehaviorJob;
|
||||
use App\Jobs\RecComputeSimilarHybridJob;
|
||||
use App\Models\ArtworkFavourite;
|
||||
use App\Services\UserStatsService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -24,6 +26,9 @@ class ArtworkFavouriteObserver
|
||||
if ($creatorId) {
|
||||
$this->userStats->incrementFavoritesReceived($creatorId);
|
||||
}
|
||||
|
||||
// §7.5 On-demand: recompute behavior similarity when artwork reaches threshold
|
||||
$this->maybeRecomputeBehavior($favourite->artwork_id);
|
||||
}
|
||||
|
||||
public function deleted(ArtworkFavourite $favourite): void
|
||||
@@ -42,4 +47,22 @@ class ArtworkFavouriteObserver
|
||||
|
||||
return $id !== null ? (int) $id : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch on-demand behavior recomputation when an artwork crosses a
|
||||
* favourites threshold (5, 10, 25, 50 …).
|
||||
*/
|
||||
private function maybeRecomputeBehavior(int $artworkId): void
|
||||
{
|
||||
$count = (int) DB::table('artwork_favourites')
|
||||
->where('artwork_id', $artworkId)
|
||||
->count();
|
||||
|
||||
$thresholds = [5, 10, 25, 50, 100];
|
||||
|
||||
if (in_array($count, $thresholds, true)) {
|
||||
RecComputeSimilarByBehaviorJob::dispatch($artworkId)->delay(now()->addSeconds(30));
|
||||
RecComputeSimilarHybridJob::dispatch($artworkId)->delay(now()->addMinute());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user