1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Update quering the language/locale using Cache instead of DB

This commit is contained in:
Benjamin Beganović 2021-03-22 14:09:29 +01:00
parent 535d9ae471
commit e78fb7e891
2 changed files with 12 additions and 4 deletions

View File

@ -16,6 +16,7 @@ use App\Http\Controllers\Controller;
use App\Models\BillingSubscription;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
@ -41,7 +42,9 @@ class BillingSubscriptionPurchaseController extends Controller
*/
private function setLocale(string $locale): void
{
$record = DB::table('languages')->where('locale', $locale)->first();
$record = Cache::get('languages')->filter(function ($item) use ($locale) {
return $item->locale == $locale;
})->first();
if ($record) {
App::setLocale($record->locale);

View File

@ -17,6 +17,7 @@ use App\Models\ClientContact;
use App\Models\Invoice;
use App\Repositories\ClientContactRepository;
use App\Repositories\ClientRepository;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
@ -199,7 +200,11 @@ class BillingPortalPurchase extends Component
];
if (array_key_exists('locale', $this->request_data)) {
$record = DB::table('languages')->where('locale', $this->request_data['locale'])->first();
$request = $this->request_data;
$record = Cache::get('languages')->filter(function ($item) use ($request) {
return $item->locale == $request['locale'];
})->first();
if ($record) {
$data['settings']['language_id'] = (string)$record->id;
@ -323,11 +328,11 @@ class BillingPortalPurchase extends Component
if ($option == 'increment') {
$this->quantity++;
return $this->price = (int) $this->price + $this->billing_subscription->product->price;
return $this->price = (int)$this->price + $this->billing_subscription->product->price;
}
$this->quantity--;
$this->price = (int) $this->price - $this->billing_subscription->product->price;
$this->price = (int)$this->price - $this->billing_subscription->product->price;
return 0;
}