Zum Hauptinhalt springen

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

MethodParameterReturnBeschreibung
getLeaderProfileIds()string $platformarray<int>IDs der Profile, die aktuell in Leaderboards erscheinen
getCandidateProfileIds()string $platformarray<int>IDs der Kandidaten-Profile (potentielle Leaderboard-Einsteiger)
getPriorityProfileIds()string $platformarray<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 $limitPerMetric Profile 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-KeyDefaultBeschreibung
postbox.youtube_rotation_days3YouTube-Rotation (alle X Tage)
postbox.instagram_rotation_days3Instagram-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

  • LeaderboardSnapshot Model, SocialProfileExploreMetrics Model, SocialProfile Model
  • 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)CommandAufgabe
00:10dashboard:rollup-daily-metricsTägliche Metriken-Rollups berechnen
00:15dashboard:rollup-leaderboardsWorkspace-Leaderboard-Snapshots erstellen
00:20dashboard:rollup-global-leaderboardsGlobale 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