Dashboard Services
Die Dashboard-Services steuern die Berechnung von Leaderboard-Snapshots und die Priorisierung von Profilen für tägliche Scrape-Zyklen. Sie bilden die Grundlage für das Dashboard-Rollup-System und die intelligente Ressourcenverteilung.
LeaderboardPriorityService
Location: app/Services/Dashboard/LeaderboardPriorityService.php
Bestimmt, welche Profile bei täglichen Scrape-Zyklen bevorzugt behandelt werden. Das System unterscheidet zwischen Leaders (Top-Profile in Workspace-Leaderboards) und Candidates (potentielle Aufsteiger), die beide Priority-Scraping erhalten.
Public Methods
| Method | Parameter | Return | Beschreibung |
|---|---|---|---|
getLeaderProfileIds() | string $platform | array<int> | IDs der Profile, die aktuell in Leaderboards erscheinen |
getCandidateProfileIds() | string $platform | array<int> | IDs der Kandidaten-Profile (potentielle Leaderboard-Einsteiger) |
getPriorityProfileIds() | string $platform | array<int> | Vereinigung von Leaders + Candidates |
Leader-Erkennung
Leaders sind Profile, die aktuell in einem oder mehreren Workspace-Leaderboard-Snapshots der letzten 7 Tage vertreten sind. Diese Profile haben direkten Einfluss auf die Dashboard-Darstellung und müssen daher täglich aktuell sein.
// Vereinfacht: Profile aus aktuellen Leaderboard-Snapshots
LeaderboardSnapshot::query()
->where('date', '>=', now()->subDays(7))
->distinct()
->pluck('social_profile_id');
Candidate-Erkennung
Candidates sind Profile, die das Potential haben, in Leaderboards aufzusteigen. Die Erkennung basiert auf den hoechsten Werten in den dashboard_daily_rollups der letzten 3 Tage:
- Top-Metriken:
followers_count,following_count,video_count,post_count(jeweils Top 200) - Signifikante Deltas: Profile mit den groessten absoluten Follower-Veraenderungen
- Ausschluss: Profile, die bereits Leaders sind
- Begrenzung auf
$limitPerMetricProfile pro Metrik (Default: 200)
Die Platform-Filterung nutzt eine Subquery statt JOINs auf social_profiles, um unnoetige Query-Komplexitaet zu vermeiden:
// Einmalige Subquery fuer Platform-IDs (statt 5x JOIN)
$platformProfileIds = $platform !== null
? DB::table('social_profiles')->where('platform', $platform)->select('id')
: null;
// Verwendung per whereIn (statt JOIN + WHERE)
$query->whereIn('r.social_profile_id', $platformProfileIds);
Priority-Scraping-Integration
Der SocialScrapeDailyFollowers-Command fragt getPriorityProfileIds() ab und scraped diese Profile zuerst, bevor die reguläre Rotation greift:
Täglicher Scrape-Zyklus:
1. Priority-Profile (Leaders + Candidates) → immer scrapen
2. Rotation-Bucket (alle 3 Tage) → restliche Profile
Rotation-Bucket-System
Profile, die nicht zu den Priority-Profilen gehören, werden in Rotation-Buckets aufgeteilt:
| Config-Key | Default | Beschreibung |
|---|---|---|
postbox.youtube_rotation_days | 3 | YouTube-Rotation (alle X Tage) |
postbox.instagram_rotation_days | 3 | Instagram-Rotation (alle X Tage) |
Die Bucket-Zuweisung basiert auf profile_id % rotation_days, sodass jeden Tag ein anderes Drittel der Profile gescraped wird.
Abhängigkeiten
LeaderboardSnapshotModel,SocialProfileExploreMetricsModel,SocialProfileModel- Config:
postbox.leaderboard_candidate_limit
Verwendet von
SocialScrapeDailyFollowers-Command,QueueDailyInstagramScrapes-Command
Dashboard-Rollup-Pipeline
Die Dashboard-Datenaufbereitung erfolgt über eine Pipeline von Artisan-Commands, die vom LeaderboardPriorityService indirekt profitieren:
Rollup-Reihenfolge (Schedule)
| Zeit (UTC) | Command | Aufgabe |
|---|---|---|
| 00:10 | dashboard:rollup-daily-metrics | Tägliche Metriken-Rollups berechnen |
| 00:15 | dashboard:rollup-leaderboards | Workspace-Leaderboard-Snapshots erstellen |
| 00:20 | dashboard:rollup-global-leaderboards | Globale Leaderboard-Snapshots erstellen |
Rollup-Datenfluss
SocialProfileDailyMetric (Rohdaten)
↓
DashboardRollup (pro Workspace + Profil + Tag)
↓
LeaderboardSnapshot (pro Workspace + Metrik + Tag)
↓
GlobalLeaderboardSnapshot (systemweit + Metrik + Tag)
Support: DashboardSnapshotRefresher
Location: app/Support/DashboardSnapshotRefresher.php
Utility-Klasse, die Dashboard-Rollup-Builds queued und Stale-Detection durchführt. Wird automatisch aufgerufen, wenn neue Metriken eintreffen oder Watchers angelegt werden.
// Rollup triggern falls Snapshots veraltet sind
DashboardSnapshotRefresher::queueIfMissingSnapshots($userId);
Verwendet von
DefaultWorkspaceProvisioner, Watcher-Import, Daily Scrape Completion Events