Reduce number of queries for update check (#520)

This commit is contained in:
Nabeel S
2020-01-30 12:44:59 -05:00
committed by GitHub
parent f0719d4d8d
commit 3c1b433c29
4 changed files with 14 additions and 10 deletions
+5 -5
View File
@@ -218,6 +218,7 @@ class SeederService extends Service
*/ */
private function settingsSeedsPending(): bool private function settingsSeedsPending(): bool
{ {
$all_settings = DB::table('settings')->get();
$data = file_get_contents(database_path('/seeds/settings.yml')); $data = file_get_contents(database_path('/seeds/settings.yml'));
$yml = Yaml::parse($data); $yml = Yaml::parse($data);
@@ -228,7 +229,7 @@ class SeederService extends Service
} }
$id = Setting::formatKey($setting['key']); $id = Setting::formatKey($setting['key']);
$row = DB::table('settings')->where('id', $id)->first(); $row = $all_settings->firstWhere('id', $id);
// Doesn't exist in the table, quit early and say there is stuff pending // Doesn't exist in the table, quit early and say there is stuff pending
if (!$row) { if (!$row) {
@@ -264,14 +265,13 @@ class SeederService extends Service
*/ */
private function permissionsSeedsPending(): bool private function permissionsSeedsPending(): bool
{ {
$all_permissions = DB::table('permissions')->get();
$data = file_get_contents(database_path('/seeds/permissions.yml')); $data = file_get_contents(database_path('/seeds/permissions.yml'));
$yml = Yaml::parse($data); $yml = Yaml::parse($data);
foreach ($yml as $perm) { foreach ($yml as $perm) {
$row = DB::table('permissions') $row = $all_permissions->firstWhere('name', $perm['name']);
->where('name', $perm['name'])
->first();
if (!$row) { if (!$row) {
return true; return true;
} }
@@ -1,4 +1,4 @@
@foreach (session('flash_notification', collect())->toArray() as $message) @foreach (session('flash_notification', []) as $message)
<div class="alert alert-danger" role="alert"> <div class="alert alert-danger" role="alert">
<div class="container"> <div class="container">
<div class="alert-icon"> <div class="alert-icon">
@@ -3,6 +3,7 @@
namespace Modules\Updater\Http\Controllers; namespace Modules\Updater\Http\Controllers;
use App\Contracts\Controller; use App\Contracts\Controller;
use App\Services\Installer\InstallerService;
use App\Services\Installer\MigrationService; use App\Services\Installer\MigrationService;
use App\Services\Installer\SeederService; use App\Services\Installer\SeederService;
use function count; use function count;
@@ -11,19 +12,23 @@ use Illuminate\Support\Facades\Log;
class UpdateController extends Controller class UpdateController extends Controller
{ {
private $installerSvc;
private $migrationSvc; private $migrationSvc;
private $seederSvc; private $seederSvc;
/** /**
* @param InstallerService $installerSvc
* @param MigrationService $migrationSvc * @param MigrationService $migrationSvc
* @param SeederService $seederSvc * @param SeederService $seederSvc
*/ */
public function __construct( public function __construct(
InstallerService $installerSvc,
MigrationService $migrationSvc, MigrationService $migrationSvc,
SeederService $seederSvc SeederService $seederSvc
) { ) {
$this->migrationSvc = $migrationSvc; $this->migrationSvc = $migrationSvc;
$this->seederSvc = $seederSvc; $this->seederSvc = $seederSvc;
$this->installerSvc = $installerSvc;
} }
/** /**
@@ -44,9 +49,8 @@ class UpdateController extends Controller
*/ */
public function step1(Request $request) public function step1(Request $request)
{ {
$migrations = $this->migrationSvc->migrationsAvailable(); if ($this->installerSvc->isUpgradePending()) {
if (count($migrations) > 0) { Log::info('Upgrade is pending');
Log::info('No migrations found');
} }
return view('updater::steps/step1-update-available'); return view('updater::steps/step1-update-available');
@@ -1,4 +1,4 @@
@foreach (session('flash_notification', collect())->toArray() as $message) @foreach (session('flash_notification', []) as $message)
@if ($message['overlay']) @if ($message['overlay'])
@include('flash::modal', [ @include('flash::modal', [
'modalClass' => 'flash-modal', 'modalClass' => 'flash-modal',