feat: ship creator journey v2 and profile updates
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Services\UserStatsService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
@@ -91,6 +92,55 @@ class ArtworkStatsService
|
||||
$this->incrementDownloads((int) $artwork->id, $by, $defer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recompute denormalized engagement counters from their source tables.
|
||||
*
|
||||
* This keeps single-artwork analytics fresh after favourites, likes,
|
||||
* comments, and shares without waiting for scheduled ranking jobs.
|
||||
*/
|
||||
public function syncEngagementCounts(int $artworkId): void
|
||||
{
|
||||
if (! Schema::hasTable('artwork_stats')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$payload = [
|
||||
'favorites' => Schema::hasTable('artwork_favourites')
|
||||
? (int) DB::table('artwork_favourites')->where('artwork_id', $artworkId)->count()
|
||||
: 0,
|
||||
'rating_count' => Schema::hasTable('artwork_likes')
|
||||
? (int) DB::table('artwork_likes')->where('artwork_id', $artworkId)->count()
|
||||
: 0,
|
||||
];
|
||||
|
||||
if (Schema::hasColumn('artwork_stats', 'comments_count')) {
|
||||
$payload['comments_count'] = Schema::hasTable('artwork_comments')
|
||||
? (int) DB::table('artwork_comments')
|
||||
->where('artwork_id', $artworkId)
|
||||
->whereNull('deleted_at')
|
||||
->count()
|
||||
: 0;
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('artwork_stats', 'shares_count')) {
|
||||
$payload['shares_count'] = Schema::hasTable('artwork_shares')
|
||||
? (int) DB::table('artwork_shares')->where('artwork_id', $artworkId)->count()
|
||||
: 0;
|
||||
}
|
||||
|
||||
DB::table('artwork_stats')->updateOrInsert(
|
||||
['artwork_id' => $artworkId],
|
||||
$payload
|
||||
);
|
||||
} catch (Throwable $e) {
|
||||
Log::warning('Failed to sync artwork engagement counts', [
|
||||
'artwork_id' => $artworkId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a set of deltas to the artwork_stats row inside a transaction.
|
||||
* After updating artwork-level stats, forwards view/download counts to
|
||||
|
||||
Reference in New Issue
Block a user