Adding popularity for queued apps (#20)

This commit is contained in:
ilumos 2018-02-03 15:24:09 +00:00
parent 5d6bebb3fe
commit 04fcfed124
4 changed files with 9 additions and 3 deletions

View file

@ -53,6 +53,7 @@ class InitialiseDatabase extends Command
$table->integer('app_id'); $table->integer('app_id');
$table->string('status'); $table->string('status');
$table->string('platform'); $table->string('platform');
$table->integer('popularity')->nullable()->default(1);
$table->string('message')->nullable(); $table->string('message')->nullable();
}); });

View file

@ -81,11 +81,13 @@ class QueueUsersRecentApps extends Command
// Queue each platform separately // Queue each platform separately
foreach ($platforms as $platform) { foreach ($platforms as $platform) {
$alreadyQueued = SteamQueueItem::where('app_id', $app->appId) $existingQueueItem = SteamQueueItem::where('app_id', $app->appId)
->where('platform', $platform) ->where('platform', $platform)
->first(); ->first();
if ($alreadyQueued) { if ($existingQueueItem) {
$existingQueueItem->popularity++;
$existingQueueItem->save();
$this->warn('Steam app "' . $app->name . '" on platform "' . ucfirst($platform) . '" already in download queue'); $this->warn('Steam app "' . $app->name . '" on platform "' . ucfirst($platform) . '" already in download queue');
continue; continue;
} }

View file

@ -80,6 +80,7 @@ class ShowQueue extends Command
} }
$steamQueueItems = SteamQueueItem::where('status', $status) $steamQueueItems = SteamQueueItem::where('status', $status)
->orderBy('popularity', 'desc')
->orderBy('message') ->orderBy('message')
->get(); ->get();
@ -90,7 +91,7 @@ class ShowQueue extends Command
$this->{$messageStyle}(ucfirst($status) . ':'); $this->{$messageStyle}(ucfirst($status) . ':');
$table = new Table($this->output); $table = new Table($this->output);
$table->setHeaders(['Name', 'Platform', 'App ID', 'Message']); $table->setHeaders(['Name', 'Platform', 'Popularity', 'App ID', 'Message']);
foreach ($steamQueueItems as $steamQueueItem) { foreach ($steamQueueItems as $steamQueueItem) {
if (isset($steamQueueItem->app->name)) { if (isset($steamQueueItem->app->name)) {
@ -101,6 +102,7 @@ class ShowQueue extends Command
$table->addRow([ $table->addRow([
$appName, $appName,
ucfirst($steamQueueItem->platform), ucfirst($steamQueueItem->platform),
$steamQueueItem->popularity,
$steamQueueItem->app_id, $steamQueueItem->app_id,
$steamQueueItem->message, $steamQueueItem->message,
]); ]);

View file

@ -123,6 +123,7 @@ class StartDownloading extends Command
private function nextApp() private function nextApp()
{ {
return SteamQueueItem::where('status', 'queued') return SteamQueueItem::where('status', 'queued')
->orderBy('popularity', 'desc')
->first(); ->first();
} }