Skip to content

Commit

Permalink
Reduce number of queries for update check (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio authored Jan 30, 2020
1 parent f0719d4 commit 3c1b433
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions app/Services/Installer/SeederService.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ private function getNextOrderNumber($group): int
*/
private function settingsSeedsPending(): bool
{
$all_settings = DB::table('settings')->get();
$data = file_get_contents(database_path('/seeds/settings.yml'));
$yml = Yaml::parse($data);

Expand All @@ -228,7 +229,7 @@ private function settingsSeedsPending(): bool
}

$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
if (!$row) {
Expand Down Expand Up @@ -264,14 +265,13 @@ private function settingsSeedsPending(): bool
*/
private function permissionsSeedsPending(): bool
{
$all_permissions = DB::table('permissions')->get();

$data = file_get_contents(database_path('/seeds/permissions.yml'));
$yml = Yaml::parse($data);

foreach ($yml as $perm) {
$row = DB::table('permissions')
->where('name', $perm['name'])
->first();

$row = $all_permissions->firstWhere('name', $perm['name']);
if (!$row) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/Installer/Resources/views/flash/message.blade.php
Original file line number Diff line number Diff line change
@@ -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="container">
<div class="alert-icon">
Expand Down
10 changes: 7 additions & 3 deletions modules/Updater/Http/Controllers/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Modules\Updater\Http\Controllers;

use App\Contracts\Controller;
use App\Services\Installer\InstallerService;
use App\Services\Installer\MigrationService;
use App\Services\Installer\SeederService;
use function count;
Expand All @@ -11,19 +12,23 @@

class UpdateController extends Controller
{
private $installerSvc;
private $migrationSvc;
private $seederSvc;

/**
* @param InstallerService $installerSvc
* @param MigrationService $migrationSvc
* @param SeederService $seederSvc
*/
public function __construct(
InstallerService $installerSvc,
MigrationService $migrationSvc,
SeederService $seederSvc
) {
$this->migrationSvc = $migrationSvc;
$this->seederSvc = $seederSvc;
$this->installerSvc = $installerSvc;
}

/**
Expand All @@ -44,9 +49,8 @@ public function index()
*/
public function step1(Request $request)
{
$migrations = $this->migrationSvc->migrationsAvailable();
if (count($migrations) > 0) {
Log::info('No migrations found');
if ($this->installerSvc->isUpgradePending()) {
Log::info('Upgrade is pending');
}

return view('updater::steps/step1-update-available');
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/flash/message.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@foreach (session('flash_notification', collect())->toArray() as $message)
@foreach (session('flash_notification', []) as $message)
@if ($message['overlay'])
@include('flash::modal', [
'modalClass' => 'flash-modal',
Expand Down

0 comments on commit 3c1b433

Please sign in to comment.