Run steam apps update in background once a month

This commit is contained in:
DariusIII
2024-09-13 20:50:26 +02:00
parent e2a4e0cd46
commit 5d59261b7a
3 changed files with 19 additions and 78 deletions
+18 -45
View File
@@ -2,7 +2,6 @@
namespace Blacklight;
use App\Models\Settings;
use App\Models\SteamApp;
use b3rs3rk\steamfront\Main;
use DivineOmega\CliProgressBar\ProgressBar;
@@ -96,8 +95,6 @@ class Steam
return false;
}
$this->populateSteamAppsTable();
$results = SteamApp::search($searchTerm)->get();
if ($results instanceof \Traversable) {
@@ -136,51 +133,27 @@ class Steam
public function populateSteamAppsTable(): void
{
$bar = new ProgressBar;
$lastUpdate = Settings::settingValue('APIs.Steam.last_update');
$this->lastUpdate = $lastUpdate > 0 ? $lastUpdate : 0;
if ((time() - (int) $this->lastUpdate) > 86400) {
// Set time we updated steam_apps table
$this->setLastUpdated();
$fullAppArray = $this->steamFront->getFullAppList();
$inserted = $dupe = 0;
$this->colorCli->info('Populating steam apps table');
$appsArray = Arr::pluck($fullAppArray, 'apps');
$max = count($appsArray[0]);
$bar->setMaxProgress($max);
foreach ($appsArray as $appArray) {
foreach ($appArray as $app) {
$dupeCheck = SteamApp::query()->where('appid', '=', $app['appid'])->first(['appid']);
if ($dupeCheck === null) {
SteamApp::query()->insert(['name' => $app['name'], 'appid' => $app['appid']]);
$inserted++;
} else {
$dupe++;
}
$bar->advance()->display();
$fullAppArray = $this->steamFront->getFullAppList();
$inserted = $dupe = 0;
$this->colorCli->info('Populating steam apps table');
$appsArray = Arr::pluck($fullAppArray, 'apps');
$max = count($appsArray[0]);
$bar->setMaxProgress($max);
foreach ($appsArray as $appArray) {
foreach ($appArray as $app) {
$dupeCheck = SteamApp::query()->where('appid', '=', $app['appid'])->first(['appid']);
if ($dupeCheck === null) {
SteamApp::query()->insert(['name' => $app['name'], 'appid' => $app['appid']]);
$inserted++;
} else {
$dupe++;
}
$bar->advance()->display();
}
$bar->complete();
echo PHP_EOL.'Added '.$inserted.' new steam app(s), '.$dupe.' duplicates skipped'.PHP_EOL;
}
}
/**
* Sets the database time for last full Steam update.
*/
private function setLastUpdated(): void
{
Settings::query()->where(
[
['section', '=', 'APIs'],
['subsection', '=', 'Steam'],
['name', '=', 'last_update'],
]
)->update(
[
'value' => time(),
]
);
$bar->complete();
\Laravel\Prompts\info('Added '.$inserted.' new steam app(s), '.$dupe.' duplicates skipped');
}
}
@@ -1,33 +0,0 @@
<?php
namespace App\Console\Commands;
use Blacklight\Steam;
use Illuminate\Console\Command;
class NntmuxPopulateSteam extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'nntmux:populate-steam';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Populate Steam Apps table';
/**
* Execute the console command.
*/
public function handle(): void
{
$steam = new Steam;
$steam->populateSteamAppsTable();
}
}
+1
View File
@@ -29,6 +29,7 @@ Schedule::command('horizon:snapshot')->everyFiveMinutes()->withoutOverlapping();
Schedule::command('cloudflare:reload')->daily();
Schedule::command('cache:prune-stale-tags')->hourly();
Schedule::command('nntmux:collect-stats')->hourly();
Schedule::command('nntmux:populate-steam-apps')->monthly();
if (config('nntmux.purge_inactive_users') === true) {
Schedule::job(new RemoveInactiveAccounts)->daily();
}