1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Remove cache warmers

This commit is contained in:
David Bomba 2024-06-21 10:56:18 +10:00
parent 5ddda5aa33
commit a65d0d5067
7 changed files with 0 additions and 271 deletions

View File

@ -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);
}
}
}
}

View File

@ -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')) {

View File

@ -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);
}
}
}
}
}

View File

@ -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);
}
}
}
}
}

View File

@ -1,109 +0,0 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Middleware;
use App\DataMapper\EmailTemplateDefaults;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Schema;
/**
* Class StartupCheck.
*/
class StartupCheck
{
/**
* Handle an incoming request.
* @deprecated
* @param Request $request
* @param Closure $next
*
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
// $start = microtime(true);
/* Make sure our cache is built */
$cached_tables = config('ninja.cached_tables');
foreach ($cached_tables as $name => $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);
}
}

View File

@ -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;

View File

@ -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();