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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Artwork;
|
||||
use App\Jobs\RecComputeSimilarByTagsJob;
|
||||
use App\Jobs\RecComputeSimilarHybridJob;
|
||||
use App\Services\ArtworkSearchIndexer;
|
||||
use App\Services\UserStatsService;
|
||||
|
||||
@@ -39,6 +41,14 @@ class ArtworkObserver
|
||||
}
|
||||
|
||||
$this->indexer->update($artwork);
|
||||
|
||||
// §7.5 On-demand: recompute similarity when tags/categories could have changed.
|
||||
// The pivot sync happens outside this observer, so we dispatch on every
|
||||
// meaningful update and let the job be idempotent (cheap if nothing changed).
|
||||
if ($artwork->is_public && $artwork->published_at) {
|
||||
RecComputeSimilarByTagsJob::dispatch($artwork->id)->delay(now()->addSeconds(30));
|
||||
RecComputeSimilarHybridJob::dispatch($artwork->id)->delay(now()->addMinutes(1));
|
||||
}
|
||||
}
|
||||
|
||||
/** Soft delete — remove from search and decrement uploads_count. */
|
||||
|
||||
Reference in New Issue
Block a user