Wire admin studio SSR and search infrastructure
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Models\BlogPost;
|
||||
use App\Services\ThumbnailPresenter;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
@@ -50,7 +51,6 @@ final class ErrorSuggestionService
|
||||
|
||||
return Cache::remember("error_suggestions.similar_tags.{$slug}.{$limit}", self::CACHE_TTL, function () use ($slug, $limit, $prefix) {
|
||||
return Tag::query()
|
||||
->withCount('artworks')
|
||||
->where('slug', '!=', $slug)
|
||||
->where(function ($q) use ($prefix, $slug) {
|
||||
$q->where('slug', 'like', $prefix . '%')
|
||||
@@ -70,7 +70,6 @@ final class ErrorSuggestionService
|
||||
|
||||
return Cache::remember("error_suggestions.tags.{$limit}", self::CACHE_TTL, function () use ($limit) {
|
||||
return Tag::query()
|
||||
->withCount('artworks')
|
||||
->orderByDesc('artworks_count')
|
||||
->limit($limit)
|
||||
->get(['id', 'name', 'slug', 'artworks_count']);
|
||||
@@ -84,14 +83,17 @@ final class ErrorSuggestionService
|
||||
$limit = min($limit, 6);
|
||||
|
||||
return Cache::remember("error_suggestions.creators.{$limit}", self::CACHE_TTL, function () use ($limit) {
|
||||
return User::query()
|
||||
->with('profile')
|
||||
->withCount(['artworks' => fn ($q) => $q->public()->published()])
|
||||
->having('artworks_count', '>', 0)
|
||||
->orderByDesc('artworks_count')
|
||||
return DB::table('users as u')
|
||||
->join('user_statistics as us', 'us.user_id', '=', 'u.id')
|
||||
->leftJoin('user_profiles as up', 'up.user_id', '=', 'u.id')
|
||||
->select('u.id', 'u.name', 'u.username', 'up.avatar_hash', DB::raw('us.uploads_count as artworks_count'))
|
||||
->where('u.is_active', true)
|
||||
->whereNull('u.deleted_at')
|
||||
->where('us.uploads_count', '>', 0)
|
||||
->orderByDesc('us.uploads_count')
|
||||
->limit($limit)
|
||||
->get(['users.id', 'users.name', 'users.username'])
|
||||
->map(fn (User $u) => $this->creatorCard($u, $u->artworks_count));
|
||||
->get()
|
||||
->map(fn ($u) => $this->creatorCardFromRow($u));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -102,14 +104,17 @@ final class ErrorSuggestionService
|
||||
$limit = min($limit, 6);
|
||||
|
||||
return Cache::remember("error_suggestions.creators.recent.{$limit}", self::CACHE_TTL, function () use ($limit) {
|
||||
return User::query()
|
||||
->with('profile')
|
||||
->withCount(['artworks' => fn ($q) => $q->public()->published()])
|
||||
->having('artworks_count', '>', 0)
|
||||
->orderByDesc('users.id')
|
||||
return DB::table('users as u')
|
||||
->join('user_statistics as us', 'us.user_id', '=', 'u.id')
|
||||
->leftJoin('user_profiles as up', 'up.user_id', '=', 'u.id')
|
||||
->select('u.id', 'u.name', 'u.username', 'up.avatar_hash', DB::raw('us.uploads_count as artworks_count'))
|
||||
->where('u.is_active', true)
|
||||
->whereNull('u.deleted_at')
|
||||
->where('us.uploads_count', '>', 0)
|
||||
->orderByDesc('u.id')
|
||||
->limit($limit)
|
||||
->get(['users.id', 'users.name', 'users.username'])
|
||||
->map(fn (User $u) => $this->creatorCard($u, $u->artworks_count));
|
||||
->get()
|
||||
->map(fn ($u) => $this->creatorCardFromRow($u));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -166,4 +171,20 @@ final class ErrorSuggestionService
|
||||
'artworks_count' => $artworksCount,
|
||||
];
|
||||
}
|
||||
|
||||
private function creatorCardFromRow(object $u): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) $u->id,
|
||||
'name' => $u->name ?: $u->username,
|
||||
'username' => $u->username,
|
||||
'url' => '/@' . $u->username,
|
||||
'avatar_url' => \App\Support\AvatarUrl::forUser(
|
||||
(int) $u->id,
|
||||
$u->avatar_hash ?? null,
|
||||
64
|
||||
),
|
||||
'artworks_count' => (int) ($u->artworks_count ?? 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user