From a65d0d506754c89f1d91792fac89f194aca632bb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 21 Jun 2024 10:56:18 +1000 Subject: [PATCH] Remove cache warmers --- app/Console/Commands/CreateAccount.php | 22 ---- app/Console/Commands/CreateSingleAccount.php | 30 ----- app/Console/Commands/CreateTestData.php | 29 ----- app/Console/Commands/DemoMode.php | 29 ----- app/Http/Middleware/StartupCheck.php | 109 ------------------- tests/Feature/Export/UserSalesReportTest.php | 25 ----- tests/MockAccountData.php | 27 ----- 7 files changed, 271 deletions(-) delete mode 100644 app/Http/Middleware/StartupCheck.php diff --git a/app/Console/Commands/CreateAccount.php b/app/Console/Commands/CreateAccount.php index f40814f28585..e62bb6bfd988 100644 --- a/app/Console/Commands/CreateAccount.php +++ b/app/Console/Commands/CreateAccount.php @@ -121,28 +121,6 @@ class CreateAccount extends Command (new CreateCompanyTaskStatuses($company, $user))->handle(); (new VersionCheck())->handle(); - $this->warmCache(); } - private function warmCache() - { - /* Warm up the cache !*/ - $cached_tables = config('ninja.cached_tables'); - - foreach ($cached_tables as $name => $class) { - if ($name == 'payment_terms') { - $orderBy = 'num_days'; - } elseif ($name == 'fonts') { - $orderBy = 'sort_order'; - } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) { - $orderBy = 'name'; - } else { - $orderBy = 'id'; - } - $tableData = $class::orderBy($orderBy)->get(); - if ($tableData->count()) { - Cache::forever($name, $tableData); - } - } - } } diff --git a/app/Console/Commands/CreateSingleAccount.php b/app/Console/Commands/CreateSingleAccount.php index f2769de649a1..50d915cca2a4 100644 --- a/app/Console/Commands/CreateSingleAccount.php +++ b/app/Console/Commands/CreateSingleAccount.php @@ -97,10 +97,6 @@ class CreateSingleAccount extends Command $this->count = 5; $this->gateway = $this->argument('gateway'); - $this->info('Warming up cache'); - - $this->warmCache(); - $this->createSmallAccount(); @@ -774,32 +770,6 @@ class CreateSingleAccount extends Command return $line_items; } - private function warmCache() - { - /* Warm up the cache !*/ - $cached_tables = config('ninja.cached_tables'); - - foreach ($cached_tables as $name => $class) { - // check that the table exists in case the migration is pending - if (! Schema::hasTable((new $class())->getTable())) { - continue; - } - if ($name == 'payment_terms') { - $orderBy = 'num_days'; - } elseif ($name == 'fonts') { - $orderBy = 'sort_order'; - } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) { - $orderBy = 'name'; - } else { - $orderBy = 'id'; - } - $tableData = $class::orderBy($orderBy)->get(); - if ($tableData->count()) { - Cache::forever($name, $tableData); - } - } - } - private function createGateways($company, $user) { if (config('ninja.testvars.stripe') && ($this->gateway == 'all' || $this->gateway == 'stripe')) { diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index 496e877c45d9..6bb5811ecb4f 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -86,8 +86,6 @@ class CreateTestData extends Command $this->info('Warming up cache'); - $this->warmCache(); - $this->createSmallAccount(); $this->createMediumAccount(); $this->createLargeAccount(); @@ -673,31 +671,4 @@ class CreateTestData extends Command return $line_items; } - private function warmCache() - { - /* Warm up the cache !*/ - $cached_tables = config('ninja.cached_tables'); - - foreach ($cached_tables as $name => $class) { - if (! Cache::has($name)) { - // check that the table exists in case the migration is pending - if (! Schema::hasTable((new $class())->getTable())) { - continue; - } - if ($name == 'payment_terms') { - $orderBy = 'num_days'; - } elseif ($name == 'fonts') { - $orderBy = 'sort_order'; - } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) { - $orderBy = 'name'; - } else { - $orderBy = 'id'; - } - $tableData = $class::orderBy($orderBy)->get(); - if ($tableData->count()) { - Cache::forever($name, $tableData); - } - } - } - } } diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index 11169d5832d5..8e4014d1ef17 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -84,8 +84,6 @@ class DemoMode extends Command $this->invoice_repo = new InvoiceRepository(); - $cached_tables = config('ninja.cached_tables'); - $this->info('Migrating'); Artisan::call('migrate:fresh --force'); @@ -623,31 +621,4 @@ class DemoMode extends Command return $line_items; } - private function warmCache() - { - /* Warm up the cache !*/ - $cached_tables = config('ninja.cached_tables'); - - foreach ($cached_tables as $name => $class) { - if (! Cache::has($name)) { - // check that the table exists in case the migration is pending - if (! Schema::hasTable((new $class())->getTable())) { - continue; - } - if ($name == 'payment_terms') { - $orderBy = 'num_days'; - } elseif ($name == 'fonts') { - $orderBy = 'sort_order'; - } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) { - $orderBy = 'name'; - } else { - $orderBy = 'id'; - } - $tableData = $class::orderBy($orderBy)->get(); - if ($tableData->count()) { - Cache::forever($name, $tableData); - } - } - } - } } diff --git a/app/Http/Middleware/StartupCheck.php b/app/Http/Middleware/StartupCheck.php deleted file mode 100644 index 75a4a010c951..000000000000 --- a/app/Http/Middleware/StartupCheck.php +++ /dev/null @@ -1,109 +0,0 @@ - $class) { - if ($request->has('clear_cache') || ! Cache::has($name)) { - // check that the table exists in case the migration is pending - if (! Schema::hasTable((new $class())->getTable())) { - continue; - } - if ($name == 'payment_terms') { - $orderBy = 'num_days'; - } elseif ($name == 'fonts') { - $orderBy = 'sort_order'; - } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) { - $orderBy = 'name'; - } else { - $orderBy = 'id'; - } - $tableData = $class::orderBy($orderBy)->get(); - if ($tableData->count()) { - Cache::forever($name, $tableData); - } - } - } - - /*Build template cache*/ - if ($request->has('clear_cache') || ! Cache::has('templates')) { - $this->buildTemplates(); - } - - return $next($request); - } - - private function buildTemplates($name = 'templates') - { - $data = [ - 'invoice' => [ - 'subject' => EmailTemplateDefaults::emailInvoiceSubject(), - 'body' => EmailTemplateDefaults::emailInvoiceTemplate(), - ], - 'quote' => [ - 'subject' => EmailTemplateDefaults::emailQuoteSubject(), - 'body' => EmailTemplateDefaults::emailQuoteTemplate(), - ], - 'payment' => [ - 'subject' => EmailTemplateDefaults::emailPaymentSubject(), - 'body' => EmailTemplateDefaults::emailPaymentTemplate(), - ], - 'reminder1' => [ - 'subject' => EmailTemplateDefaults::emailReminder1Subject(), - 'body' => EmailTemplateDefaults::emailReminder1Template(), - ], - 'reminder2' => [ - 'subject' => EmailTemplateDefaults::emailReminder2Subject(), - 'body' => EmailTemplateDefaults::emailReminder2Template(), - ], - 'reminder3' => [ - 'subject' => EmailTemplateDefaults::emailReminder3Subject(), - 'body' => EmailTemplateDefaults::emailReminder3Template(), - ], - 'reminder_endless' => [ - 'subject' => EmailTemplateDefaults::emailReminderEndlessSubject(), - 'body' => EmailTemplateDefaults::emailReminderEndlessTemplate(), - ], - 'statement' => [ - 'subject' => EmailTemplateDefaults::emailStatementSubject(), - 'body' => EmailTemplateDefaults::emailStatementTemplate(), - ], - ]; - - Cache::forever($name, $data); - } -} diff --git a/tests/Feature/Export/UserSalesReportTest.php b/tests/Feature/Export/UserSalesReportTest.php index 2be1a220237e..76253abac29a 100644 --- a/tests/Feature/Export/UserSalesReportTest.php +++ b/tests/Feature/Export/UserSalesReportTest.php @@ -46,31 +46,6 @@ class UserSalesReportTest extends TestCase $this->withoutExceptionHandling(); - /* Warm up the cache !*/ - $cached_tables = config('ninja.cached_tables'); - - $this->artisan('db:seed --force'); - - foreach ($cached_tables as $name => $class) { - // check that the table exists in case the migration is pending - if (! Schema::hasTable((new $class())->getTable())) { - continue; - } - if ($name == 'payment_terms') { - $orderBy = 'num_days'; - } elseif ($name == 'fonts') { - $orderBy = 'sort_order'; - } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) { - $orderBy = 'name'; - } else { - $orderBy = 'id'; - } - $tableData = $class::orderBy($orderBy)->get(); - if ($tableData->count()) { - Cache::forever($name, $tableData); - } - } - } public $company; diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index 32b5e057e3f7..c2d047d2fec0 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -203,33 +203,6 @@ trait MockAccountData { config(['database.default' => config('ninja.db.default')]); - // /* Warm up the cache !*/ - // $cached_tables = config('ninja.cached_tables'); - - // Artisan::call('db:seed', [ - // '--force' => true - // ]); - - // foreach ($cached_tables as $name => $class) { - // // check that the table exists in case the migration is pending - // if (! Schema::hasTable((new $class())->getTable())) { - // continue; - // } - // if ($name == 'payment_terms') { - // $orderBy = 'num_days'; - // } elseif ($name == 'fonts') { - // $orderBy = 'sort_order'; - // } elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) { - // $orderBy = 'name'; - // } else { - // $orderBy = 'id'; - // } - // $tableData = $class::orderBy($orderBy)->get(); - // if ($tableData->count()) { - // Cache::forever($name, $tableData); - // } - // } - $this->faker = \Faker\Factory::create(); $fake_email = $this->faker->email();