From 698a376de353a29f27c91a4fb8d4503640a59a26 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 21 Jun 2024 10:29:38 +1000 Subject: [PATCH] remove cache build steps --- app/Console/Commands/DemoMode.php | 4 +- app/Console/Commands/HostedMigrations.php | 1 - app/Console/Commands/ImportMigrations.php | 2 - app/Console/Commands/PostUpdate.php | 3 +- app/DataMapper/Tax/BaseRule.php | 2 +- app/DataProviders/USStates.php | 2 +- app/Http/Controllers/ActivityController.php | 1 + app/Http/Controllers/BaseController.php | 2 - app/Http/Controllers/SelfUpdateController.php | 3 +- app/Http/Controllers/SetupController.php | 5 +- app/Providers/StaticServiceProvider.php | 145 ++++++++++++++++-- app/Utils/Traits/AppSetup.php | 65 ++------ ...3_215053_update_canadian_dollar_symbol.php | 3 +- ..._023350_update_singapore_dollar_symbol.php | 2 - ...dd_property_to_checkout_gateway_config.php | 1 - ...4937_heal_stripe_gateway_configuration.php | 1 - ...n_show_production_description_dropdown.php | 1 - ...6_080127_add_purchase_order_to_expense.php | 2 - ..._11_22_215618_lock_tasks_when_invoiced.php | 2 - ...d_payment_id_to_bank_transaction_table.php | 1 - database/seeders/RandomDataSeeder.php | 2 - tests/Feature/Client/ClientMergeTest.php | 1 - tests/Feature/ClientPortal/CreditsTest.php | 1 - tests/Feature/ClientPortal/InvoicesTest.php | 1 - tests/Feature/Export/ArDetailReportTest.php | 2 - .../Feature/Export/ProductSalesReportTest.php | 2 - tests/Integration/CompanyLedgerTest.php | 1 - tests/TestCase.php | 2 - tests/Unit/CreditBalanceTest.php | 2 - tests/Unit/RecurringExpenseCloneTest.php | 2 - 30 files changed, 147 insertions(+), 117 deletions(-) diff --git a/app/Console/Commands/DemoMode.php b/app/Console/Commands/DemoMode.php index 7ea0edb4e604..11169d5832d5 100644 --- a/app/Console/Commands/DemoMode.php +++ b/app/Console/Commands/DemoMode.php @@ -90,9 +90,9 @@ class DemoMode extends Command Artisan::call('migrate:fresh --force'); $this->info('Seeding'); - Artisan::call('db:seed --force'); - $this->buildCache(true); + Artisan::call('db:seed --force'); + Artisan::call('cache:clear'); $this->info('Seeding Random Data'); $this->createSmallAccount(); diff --git a/app/Console/Commands/HostedMigrations.php b/app/Console/Commands/HostedMigrations.php index bf83024f0729..3a005852e921 100644 --- a/app/Console/Commands/HostedMigrations.php +++ b/app/Console/Commands/HostedMigrations.php @@ -62,7 +62,6 @@ class HostedMigrations extends Command */ public function handle() { - $this->buildCache(); if (! MultiDB::userFindAndSetDb($this->option('email'))) { $this->info('Could not find a user with that email address'); diff --git a/app/Console/Commands/ImportMigrations.php b/app/Console/Commands/ImportMigrations.php index aa78739e1117..3be007aa4509 100644 --- a/app/Console/Commands/ImportMigrations.php +++ b/app/Console/Commands/ImportMigrations.php @@ -75,8 +75,6 @@ class ImportMigrations extends Command { $this->faker = Factory::create(); - $this->buildCache(); - $path = $this->option('path') ?? public_path('storage/migrations/import'); $directory = new DirectoryIterator($path); diff --git a/app/Console/Commands/PostUpdate.php b/app/Console/Commands/PostUpdate.php index 9de7b55b0710..648ebb2d6966 100644 --- a/app/Console/Commands/PostUpdate.php +++ b/app/Console/Commands/PostUpdate.php @@ -86,8 +86,7 @@ class PostUpdate extends Command info('queue restarted'); - $this->buildCache(true); - + Artisan::call('cache:clear'); VersionCheck::dispatch(); info('Sent for version check'); diff --git a/app/DataMapper/Tax/BaseRule.php b/app/DataMapper/Tax/BaseRule.php index dca4576c6e3d..78eb1bd9445b 100644 --- a/app/DataMapper/Tax/BaseRule.php +++ b/app/DataMapper/Tax/BaseRule.php @@ -262,7 +262,7 @@ class BaseRule implements RuleInterface return $this->client->state; } - return USStates::getState(strlen($this->client->postal_code) > 1 ? $this->client->postal_code : $this->client->shipping_postal_code); + return USStates::getState(strlen($this->client->postal_code ?? '') > 1 ? $this->client->postal_code : $this->client->shipping_postal_code); } catch (\Exception $e) { return 'CA'; diff --git a/app/DataProviders/USStates.php b/app/DataProviders/USStates.php index 666f9356ef2a..a638bca2f937 100644 --- a/app/DataProviders/USStates.php +++ b/app/DataProviders/USStates.php @@ -34006,7 +34006,7 @@ class USStates 'WA', 'WA', 'WA', 'WA', 'WA', 'WA', 'WA', 'AK', 'AK', 'AK', 'AK', 'AK' ]; - $prefix = substr($zip, 0, 3); + $prefix = substr(($zip ?? ''), 0, 3); $index = intval($prefix); /* converts prefix to integer */ return $zip_by_state[$index] == "--" ? false : $zip_by_state[$index]; diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 0abd534023b4..dac6478f326b 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -203,6 +203,7 @@ class ActivityController extends BaseController $activity->notes = $request->notes; $activity->user_id = $user->id; $activity->ip = $request->ip(); + $activity->activity_type_id = Activity::USER_NOTE; switch (get_class($entity)) { case Invoice::class: diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index e9b7fcc96dfa..dbd7545e9dc1 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -1158,8 +1158,6 @@ class BaseController extends Controller $data['path'] = $this->setBuild(); - $this->buildCache(); - if (Ninja::isSelfHost() && $account->set_react_as_default_ap) { return response()->view('react.index', $data)->header('X-Frame-Options', 'SAMEORIGIN', false); } else { diff --git a/app/Http/Controllers/SelfUpdateController.php b/app/Http/Controllers/SelfUpdateController.php index c5c2f07f2398..09127929bd77 100644 --- a/app/Http/Controllers/SelfUpdateController.php +++ b/app/Http/Controllers/SelfUpdateController.php @@ -112,8 +112,7 @@ class SelfUpdateController extends BaseController Artisan::call('view:clear'); Artisan::call('migrate', ['--force' => true]); Artisan::call('config:clear'); - - $this->buildCache(true); + Artisan::call('cache:clear'); $this->runModelChecks(); diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index 7c91dc91a019..eadc26b0fd74 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -159,8 +159,6 @@ class SetupController extends Controller (new VersionCheck())->handle(); - $this->buildCache(true); - return redirect('/'); } catch (Exception $e) { nlog($e->getMessage()); @@ -287,8 +285,7 @@ class SetupController extends Controller Artisan::call('migrate', ['--force' => true]); Artisan::call('db:seed', ['--force' => true]); - - $this->buildCache(true); + Artisan::call('cache:clear'); (new SchedulerCheck())->handle(); diff --git a/app/Providers/StaticServiceProvider.php b/app/Providers/StaticServiceProvider.php index 77dc905535a4..8b03c2e8a2e6 100644 --- a/app/Providers/StaticServiceProvider.php +++ b/app/Providers/StaticServiceProvider.php @@ -23,6 +23,7 @@ use App\Models\DateFormat; use App\Models\PaymentTerm; use App\Models\PaymentType; use App\Models\DatetimeFormat; +use Illuminate\Support\Facades\Cache; use Illuminate\Support\ServiceProvider; use App\DataMapper\EmailTemplateDefaults; @@ -37,62 +38,174 @@ class StaticServiceProvider extends ServiceProvider { /** @return \Illuminate\Support\Collection */ app()->singleton('currencies', function ($app) { - return Currency::query()->orderBy('name')->get(); + + if($resource = Cache::get('currencies')) { + return $resource; + } + + $resource = Currency::query()->orderBy('name')->get(); + + Cache::forever('currencies', $resource); + + return $resource; + }); /** @return \Illuminate\Support\Collection */ app()->singleton('languages', function ($app) { - return Language::query()->orderBy('name')->get(); + + if($resource = Cache::get('languages')) { + return $resource; + } + + $resource = Language::query()->orderBy('name')->get(); + + Cache::forever('languages', $resource); + + return $resource; + }); /** @return \Illuminate\Support\Collection */ app()->singleton('countries', function ($app) { - return Country::query()->orderBy('name')->get(); + + if($resource = Cache::get('countries')) { + return $resource; + } + + $resource = Country::query()->orderBy('name')->get(); + + Cache::forever('countries', $resource); + + return $resource; + }); /** @return \Illuminate\Support\Collection */ app()->singleton('payment_types', function ($app) { - return PaymentType::query()->orderBy('id')->get(); + + if($resource = Cache::get('payment_types')) { + return $resource; + } + + $resource = PaymentType::query()->orderBy('id')->get(); + + Cache::forever('payment_types', $resource); + + return $resource; + }); - /** @return \Illuminate\Support\Collection */ - app()->singleton('industries', function ($app) { - return Industry::query()->orderBy('name')->get(); - }); /** @return \Illuminate\Support\Collection */ app()->singleton('banks', function ($app) { - return Bank::query()->orderBy('name')->get(); + + + if($resource = Cache::get('banks')) { + return $resource; + } + + $resource = Bank::query()->orderBy('name')->get(); + + Cache::forever('banks', $resource); + + return $resource; + }); /** @return \Illuminate\Support\Collection */ app()->singleton('date_formats', function ($app) { - return DateFormat::query()->orderBy('id')->get(); + + + if($resource = Cache::get('date_formats')) { + return $resource; + } + + $resource = DateFormat::query()->orderBy('id')->get(); + + Cache::forever('date_formats', $resource); + + return $resource; + }); /** @return \Illuminate\Support\Collection */ app()->singleton('timezones', function ($app) { - return Timezone::query()->orderBy('id')->get(); + + + if($resource = Cache::get('timezones')) { + return $resource; + } + + $resource = Timezone::query()->orderBy('id')->get(); + + Cache::forever('timezones', $resource); + + return $resource; + }); - + /** @return \Illuminate\Support\Collection */ app()->singleton('gateways', function ($app) { - return Gateway::query()->orderBy('id')->get(); + + if($resource = Cache::get('gateways')) { + return $resource; + } + + $resource = Gateway::query()->orderBy('id')->get(); + + Cache::forever('gateways', $resource); + + return $resource; + + }); /** @return \Illuminate\Support\Collection */ app()->singleton('industries', function ($app) { - return Industry::query()->orderBy('id')->get(); + + + if($resource = Cache::get('industries')) { + return $resource; + } + + $resource = Industry::query()->orderBy('id')->get(); + + Cache::forever('industries', $resource); + + return $resource; + }); /** @return \Illuminate\Support\Collection */ app()->singleton('sizes', function ($app) { - return Size::query()->orderBy('id')->get(); + + + if($resource = Cache::get('sizes')) { + return $resource; + } + + $resource = Size::query()->orderBy('id')->get(); + + Cache::forever('sizes', $resource); + + return $resource; + }); /** @return \Illuminate\Support\Collection */ app()->singleton('datetime_formats', function ($app) { - return DatetimeFormat::query()->orderBy('id')->get(); + + if($resource = Cache::get('datetime_formats')) { + return $resource; + } + + $resource = DatetimeFormat::query()->orderBy('id')->get(); + + Cache::forever('datetime_formats', $resource); + + return $resource; + }); app()->singleton('templates', function ($app) { diff --git a/app/Utils/Traits/AppSetup.php b/app/Utils/Traits/AppSetup.php index f95e398f85a2..bd39635136f6 100644 --- a/app/Utils/Traits/AppSetup.php +++ b/app/Utils/Traits/AppSetup.php @@ -29,9 +29,17 @@ trait AppSetup return $check['system_health'] == 'true'; } - + + /** + * @deprecated + * + * @param mixed $force + * @return void + */ public function buildCache($force = false) { + return; + $cached_tables = config('ninja.cached_tables'); foreach ($cached_tables as $name => $class) { @@ -53,61 +61,6 @@ trait AppSetup } /*Build template cache*/ - $this->buildTemplates(); - } - - 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(), - ], - 'payment_partial' => [ - 'subject' => EmailTemplateDefaults::emailPaymentPartialSubject(), - 'body' => EmailTemplateDefaults::emailPaymentPartialTemplate(), - ], - '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(), - ], - 'credit' => [ - 'subject' => EmailTemplateDefaults::emailCreditSubject(), - 'body' => EmailTemplateDefaults::emailCreditTemplate(), - ], - 'purchase_order' => [ - 'subject' => EmailTemplateDefaults::emailPurchaseOrderSubject(), - 'body' => EmailTemplateDefaults::emailPurchaseOrderTemplate(), - ], - ]; - - Cache::forever($name, $data); } private function updateEnvironmentProperty(string $property, $value): void diff --git a/database/migrations/2021_01_03_215053_update_canadian_dollar_symbol.php b/database/migrations/2021_01_03_215053_update_canadian_dollar_symbol.php index 0a8d5c9204c0..43ea32fd5b8a 100644 --- a/database/migrations/2021_01_03_215053_update_canadian_dollar_symbol.php +++ b/database/migrations/2021_01_03_215053_update_canadian_dollar_symbol.php @@ -19,8 +19,7 @@ return new class extends Migration { if ($currency) { $currency->update(['symbol' => '$']); } - - $this->buildCache(true); + } /** diff --git a/database/migrations/2021_01_07_023350_update_singapore_dollar_symbol.php b/database/migrations/2021_01_07_023350_update_singapore_dollar_symbol.php index 1915a4cfdee6..30a64c7f8403 100644 --- a/database/migrations/2021_01_07_023350_update_singapore_dollar_symbol.php +++ b/database/migrations/2021_01_07_023350_update_singapore_dollar_symbol.php @@ -19,8 +19,6 @@ return new class extends Migration { if ($currency) { $currency->update(['symbol' => '$']); } - - $this->buildCache(true); } /** diff --git a/database/migrations/2021_04_22_110240_add_property_to_checkout_gateway_config.php b/database/migrations/2021_04_22_110240_add_property_to_checkout_gateway_config.php index 734063651bb8..ba55cc317150 100644 --- a/database/migrations/2021_04_22_110240_add_property_to_checkout_gateway_config.php +++ b/database/migrations/2021_04_22_110240_add_property_to_checkout_gateway_config.php @@ -36,7 +36,6 @@ return new class extends Migration { $checkout->save(); }); - // $this->buildCache(true); } /** diff --git a/database/migrations/2022_05_08_004937_heal_stripe_gateway_configuration.php b/database/migrations/2022_05_08_004937_heal_stripe_gateway_configuration.php index e12fafc9982f..b7c71804a628 100644 --- a/database/migrations/2022_05_08_004937_heal_stripe_gateway_configuration.php +++ b/database/migrations/2022_05_08_004937_heal_stripe_gateway_configuration.php @@ -34,7 +34,6 @@ return new class extends Migration { $record->save(); } - $this->buildCache(true); } } diff --git a/database/migrations/2022_05_23_050754_drop_redundant_column_show_production_description_dropdown.php b/database/migrations/2022_05_23_050754_drop_redundant_column_show_production_description_dropdown.php index 4574df9e7dbc..2a5569b59202 100644 --- a/database/migrations/2022_05_23_050754_drop_redundant_column_show_production_description_dropdown.php +++ b/database/migrations/2022_05_23_050754_drop_redundant_column_show_production_description_dropdown.php @@ -19,7 +19,6 @@ return new class extends Migration { $table->dropColumn('show_production_description_dropdown'); }); - $this->buildCache(true); } /** diff --git a/database/migrations/2022_07_06_080127_add_purchase_order_to_expense.php b/database/migrations/2022_07_06_080127_add_purchase_order_to_expense.php index 741b54b3999b..510c50b62f17 100644 --- a/database/migrations/2022_07_06_080127_add_purchase_order_to_expense.php +++ b/database/migrations/2022_07_06_080127_add_purchase_order_to_expense.php @@ -36,8 +36,6 @@ class AddPurchaseOrderToExpense extends Migration if (!$language) { Language::unguard(); Language::create(['id' => 36, 'name' => 'Bulgarian', 'locale' => 'bg']); - - $this->buildCache(true); } } diff --git a/database/migrations/2022_11_22_215618_lock_tasks_when_invoiced.php b/database/migrations/2022_11_22_215618_lock_tasks_when_invoiced.php index 29bb60d3f649..ec7807063e35 100644 --- a/database/migrations/2022_11_22_215618_lock_tasks_when_invoiced.php +++ b/database/migrations/2022_11_22_215618_lock_tasks_when_invoiced.php @@ -60,8 +60,6 @@ return new class extends Migration { } \Illuminate\Support\Facades\Artisan::call('ninja:design-update'); - - $this->buildCache(true); } /** diff --git a/database/migrations/2022_11_30_063229_add_payment_id_to_bank_transaction_table.php b/database/migrations/2022_11_30_063229_add_payment_id_to_bank_transaction_table.php index affa8ec6ff57..4ede57e4b06f 100644 --- a/database/migrations/2022_11_30_063229_add_payment_id_to_bank_transaction_table.php +++ b/database/migrations/2022_11_30_063229_add_payment_id_to_bank_transaction_table.php @@ -21,7 +21,6 @@ return new class extends Migration { \Illuminate\Support\Facades\Artisan::call('ninja:design-update'); - $this->buildCache(true); } /** diff --git a/database/seeders/RandomDataSeeder.php b/database/seeders/RandomDataSeeder.php index 16d7d4e42154..9e134dcf8ef1 100644 --- a/database/seeders/RandomDataSeeder.php +++ b/database/seeders/RandomDataSeeder.php @@ -59,8 +59,6 @@ class RandomDataSeeder extends Seeder public function run() { - $this->buildCache(true); - $this->command->info('Running RandomDataSeeder'); Model::unguard(); diff --git a/tests/Feature/Client/ClientMergeTest.php b/tests/Feature/Client/ClientMergeTest.php index d6ff8069412a..a11ca2d0fcd5 100644 --- a/tests/Feature/Client/ClientMergeTest.php +++ b/tests/Feature/Client/ClientMergeTest.php @@ -44,7 +44,6 @@ class ClientMergeTest extends TestCase parent::setUp(); $this->faker = Factory::create(); - $this->buildCache(true); } public function testSearchingForContacts() diff --git a/tests/Feature/ClientPortal/CreditsTest.php b/tests/Feature/ClientPortal/CreditsTest.php index 139694be153f..9f3f0e88fb65 100644 --- a/tests/Feature/ClientPortal/CreditsTest.php +++ b/tests/Feature/ClientPortal/CreditsTest.php @@ -40,7 +40,6 @@ class CreditsTest extends TestCase parent::setUp(); $this->faker = Factory::create(); - $this->buildCache(true); } diff --git a/tests/Feature/ClientPortal/InvoicesTest.php b/tests/Feature/ClientPortal/InvoicesTest.php index 3aab7fcd7c01..581dbf1d2405 100644 --- a/tests/Feature/ClientPortal/InvoicesTest.php +++ b/tests/Feature/ClientPortal/InvoicesTest.php @@ -37,7 +37,6 @@ class InvoicesTest extends TestCase parent::setUp(); $this->faker = Factory::create(); - $this->buildCache(true); } public function testInvoiceTableFilters() diff --git a/tests/Feature/Export/ArDetailReportTest.php b/tests/Feature/Export/ArDetailReportTest.php index cfd3ddc6d899..c623936fb3db 100644 --- a/tests/Feature/Export/ArDetailReportTest.php +++ b/tests/Feature/Export/ArDetailReportTest.php @@ -45,8 +45,6 @@ class ArDetailReportTest extends TestCase ); $this->withoutExceptionHandling(); - - $this->buildCache(true); } diff --git a/tests/Feature/Export/ProductSalesReportTest.php b/tests/Feature/Export/ProductSalesReportTest.php index f530acb3f3ec..8e86dd4c8f72 100644 --- a/tests/Feature/Export/ProductSalesReportTest.php +++ b/tests/Feature/Export/ProductSalesReportTest.php @@ -47,8 +47,6 @@ class ProductSalesReportTest extends TestCase ); $this->withoutExceptionHandling(); - - $this->buildCache(true); } public $company; diff --git a/tests/Integration/CompanyLedgerTest.php b/tests/Integration/CompanyLedgerTest.php index 6ee1bce7f5e9..4086f00ba55d 100644 --- a/tests/Integration/CompanyLedgerTest.php +++ b/tests/Integration/CompanyLedgerTest.php @@ -57,7 +57,6 @@ class CompanyLedgerTest extends TestCase $this->withoutExceptionHandling(); $this->artisan('db:seed --force'); - $this->buildCache(true); $this->faker = \Faker\Factory::create(); $fake_email = $this->faker->email(); diff --git a/tests/TestCase.php b/tests/TestCase.php index ffa0f237e183..a56725512a72 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -14,7 +14,5 @@ abstract class TestCase extends BaseTestCase { parent::setUp(); - $this->buildCache(true); - } } diff --git a/tests/Unit/CreditBalanceTest.php b/tests/Unit/CreditBalanceTest.php index 68122c2739d0..af9b3a393fe1 100644 --- a/tests/Unit/CreditBalanceTest.php +++ b/tests/Unit/CreditBalanceTest.php @@ -33,8 +33,6 @@ class CreditBalanceTest extends TestCase }); $this->makeTestData(); - - $this->buildCache(true); } public function testCreditBalance() diff --git a/tests/Unit/RecurringExpenseCloneTest.php b/tests/Unit/RecurringExpenseCloneTest.php index 3c6d589d4297..9048e28b4882 100644 --- a/tests/Unit/RecurringExpenseCloneTest.php +++ b/tests/Unit/RecurringExpenseCloneTest.php @@ -33,8 +33,6 @@ class RecurringExpenseCloneTest extends TestCase { parent::setUp(); $this->faker = \Faker\Factory::create(); - $this->buildCache(true); - } public function testBadBase64String()