mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #7883 from turbo124/v5-develop
Improve storage performance
This commit is contained in:
commit
a22028799d
@ -515,8 +515,8 @@ class CompanyExport implements ShouldQueue
|
||||
|
||||
$path = 'backups';
|
||||
|
||||
if(!Storage::disk(config('filesystems.default'))->exists($path))
|
||||
Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
|
||||
// if(!Storage::disk(config('filesystems.default'))->exists($path))
|
||||
// Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
|
||||
|
||||
$zip_path = public_path('storage/backups/'.$file_name);
|
||||
$zip = new \ZipArchive();
|
||||
|
@ -213,11 +213,13 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
if ($pdf) {
|
||||
try {
|
||||
if (! Storage::disk($this->disk)->exists($path)) {
|
||||
Storage::disk($this->disk)->makeDirectory($path, 0775);
|
||||
}
|
||||
// if (! Storage::disk($this->disk)->exists($path)) {
|
||||
// Storage::disk($this->disk)->makeDirectory($path, 0775);
|
||||
// }
|
||||
|
||||
Storage::disk($this->disk)->put($file_path, $pdf, 'public');
|
||||
|
||||
//r2 Storage::disk($this->disk)->put($file_path, $pdf);
|
||||
} catch (\Exception $e) {
|
||||
throw new FilePermissionsFailure($e->getMessage());
|
||||
}
|
||||
|
@ -83,9 +83,23 @@ class UpdateOrCreateProduct implements ShouldQueue
|
||||
|
||||
$product = Product::withTrashed()->firstOrNew(['product_key' => $item->product_key, 'company_id' => $this->invoice->company->id]);
|
||||
|
||||
/* If a user is using placeholders in their descriptions, do not update the products */
|
||||
$string_hit = false;
|
||||
|
||||
foreach ( [':MONTH',':YEAR',':QUARTER',':WEEK'] as $string )
|
||||
{
|
||||
|
||||
if(stripos($product->notes, $string) !== FALSE) {
|
||||
$string_hit = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($string_hit)
|
||||
continue;
|
||||
|
||||
$product->product_key = $item->product_key;
|
||||
$product->notes = isset($item->notes) ? $item->notes : '';
|
||||
//$product->cost = isset($item->cost) ? $item->cost : 0; //this value shouldn't be updated.
|
||||
$product->price = isset($item->cost) ? $item->cost : 0;
|
||||
|
||||
if (! $product->id) {
|
||||
|
6
app/Jobs/Vendor/CreatePurchaseOrderPdf.php
vendored
6
app/Jobs/Vendor/CreatePurchaseOrderPdf.php
vendored
@ -100,11 +100,13 @@ class CreatePurchaseOrderPdf implements ShouldQueue
|
||||
|
||||
try{
|
||||
|
||||
if(!Storage::disk($this->disk)->exists($this->path))
|
||||
Storage::disk($this->disk)->makeDirectory($this->path, 0775);
|
||||
// if(!Storage::disk($this->disk)->exists($this->path))
|
||||
// Storage::disk($this->disk)->makeDirectory($this->path, 0775);
|
||||
|
||||
Storage::disk($this->disk)->put($this->file_path, $pdf, 'public');
|
||||
|
||||
//r2 Storage::disk($this->disk)->put($this->file_path, $pdf);
|
||||
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
|
@ -146,10 +146,17 @@ class TemplateEmail extends Mailable
|
||||
|
||||
}
|
||||
|
||||
//22-10-2022 - Performance - To improve the performance/reliability of sending emails, attaching as Data is much better, stubs in place
|
||||
foreach ($this->build_email->getAttachments() as $file) {
|
||||
if (is_string($file)) {
|
||||
// nlog($file);
|
||||
// $file_data = file_get_contents($file);
|
||||
// $this->attachData($file_data, basename($file));
|
||||
$this->attach($file);
|
||||
} elseif (is_array($file)) {
|
||||
// nlog($file['path']);
|
||||
// $file_data = file_get_contents($file['path']);
|
||||
// $this->attachData($file_data, $file['name']);
|
||||
$this->attach($file['path'], ['as' => $file['name'], 'mime' => null]);
|
||||
}
|
||||
}
|
||||
|
@ -36,15 +36,15 @@ class Backup extends BaseModel
|
||||
$filename = now()->format('Y_m_d').'_'.md5(time()).'.html';
|
||||
$file_path = $path.$filename;
|
||||
|
||||
Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
|
||||
// Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
|
||||
|
||||
Storage::disk(config('filesystems.default'))->put($file_path, $html);
|
||||
|
||||
if (Storage::disk(config('filesystems.default'))->exists($file_path)) {
|
||||
// if (Storage::disk(config('filesystems.default'))->exists($file_path)) {
|
||||
$this->html_backup = '';
|
||||
$this->filename = $file_path;
|
||||
$this->save();
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
public function deleteFile()
|
||||
|
@ -59,7 +59,8 @@ class ActivityRepository extends BaseRepository
|
||||
|
||||
$activity->save();
|
||||
|
||||
$this->createBackup($entity, $activity);
|
||||
//rate limiter
|
||||
// $this->createBackup($entity, $activity);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +83,8 @@ class ActivityRepository extends BaseRepository
|
||||
$backup = new Backup();
|
||||
$entity->load('client');
|
||||
$contact = $entity->client->primary_contact()->first();
|
||||
$backup->html_backup = $this->generateHtml($entity);
|
||||
$backup->html_backup = '';
|
||||
// $backup->html_backup = $this->generateHtml($entity);
|
||||
$backup->amount = $entity->amount;
|
||||
$backup->activity_id = $activity->id;
|
||||
$backup->json_backup = '';
|
||||
|
@ -19,9 +19,11 @@ use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Quote;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Utils\Helpers;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\SavesDocuments;
|
||||
use Google\Service\Vision\Property;
|
||||
use ReflectionClass;
|
||||
|
||||
class BaseRepository
|
||||
@ -108,32 +110,6 @@ class BaseRepository
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ids
|
||||
* @param $action
|
||||
*
|
||||
* @return int
|
||||
* @deprecated - this doesn't appear to be used anywhere?
|
||||
*/
|
||||
// public function bulk($ids, $action)
|
||||
// {
|
||||
// if (! $ids) {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// $ids = $this->transformKeys($ids);
|
||||
|
||||
// $entities = $this->findByPublicIdsWithTrashed($ids);
|
||||
|
||||
// foreach ($entities as $entity) {
|
||||
// if (auth()->user()->can('edit', $entity)) {
|
||||
// $this->$action($entity);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return count($entities);
|
||||
// }
|
||||
|
||||
/* Returns an invoice if defined as a key in the $resource array*/
|
||||
public function getInvitation($invitation, $resource)
|
||||
{
|
||||
@ -171,7 +147,7 @@ class BaseRepository
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected function alternativeSave($data, $model)
|
||||
{
|
||||
{ //$start = microtime(true);
|
||||
//forces the client_id if it doesn't exist
|
||||
if(array_key_exists('client_id', $data))
|
||||
$model->client_id = $data['client_id'];
|
||||
@ -208,9 +184,21 @@ class BaseRepository
|
||||
$model->custom_surcharge_tax3 = $client->company->custom_surcharge_taxes3;
|
||||
$model->custom_surcharge_tax4 = $client->company->custom_surcharge_taxes4;
|
||||
|
||||
if(!$model->id)
|
||||
if(!$model->id){
|
||||
$this->new_model = true;
|
||||
|
||||
if(is_array($model->line_items))
|
||||
{
|
||||
$model->line_items = (collect($model->line_items))->map(function ($item) use($model,$client) {
|
||||
|
||||
$item->notes = Helpers::processReservedKeywords($item->notes, $client);
|
||||
|
||||
return $item;
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$model->saveQuietly();
|
||||
|
||||
/* Model now persisted, now lets do some child tasks */
|
||||
@ -378,6 +366,8 @@ class BaseRepository
|
||||
|
||||
$model->save();
|
||||
|
||||
// nlog("save time = ". microtime(true) - $start);
|
||||
|
||||
return $model->fresh();
|
||||
}
|
||||
}
|
||||
|
@ -105,11 +105,14 @@ class GenerateDeliveryNote
|
||||
info($maker->getCompiledHTML());
|
||||
}
|
||||
|
||||
if (! Storage::disk($this->disk)->exists($this->invoice->client->invoice_filepath($invitation))) {
|
||||
Storage::disk($this->disk)->makeDirectory($this->invoice->client->invoice_filepath($invitation), 0775);
|
||||
}
|
||||
// if (! Storage::disk($this->disk)->exists($this->invoice->client->invoice_filepath($invitation))) {
|
||||
// Storage::disk($this->disk)->makeDirectory($this->invoice->client->invoice_filepath($invitation), 0775);
|
||||
// }
|
||||
|
||||
Storage::disk($this->disk)->put($file_path, $pdf, 'public');
|
||||
|
||||
//r2 Storage::disk($this->disk)->put($file_path, $pdf);
|
||||
|
||||
return $file_path;
|
||||
}
|
||||
}
|
||||
|
@ -218,6 +218,7 @@ class InvoiceService
|
||||
public function markDeleted()
|
||||
{
|
||||
$this->removeUnpaidGatewayFees();
|
||||
$this->deletePdf();
|
||||
|
||||
$this->invoice = (new MarkInvoiceDeleted($this->invoice))->run();
|
||||
|
||||
@ -298,6 +299,9 @@ class InvoiceService
|
||||
} elseif ($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount) {
|
||||
$this->setStatus(Invoice::STATUS_PARTIAL);
|
||||
}
|
||||
elseif($this->invoice->balance < 0) {
|
||||
$this->setStatus(Invoice::STATUS_PARTIAL);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -71,10 +71,6 @@ class MarkInvoiceDeleted extends AbstractService
|
||||
|
||||
private function adjustPaidToDateAndBalance()
|
||||
{
|
||||
// $client = $this->invoice->client->fresh();
|
||||
// $client->paid_to_date += $this->adjustment_amount * -1;
|
||||
// $client->balance += $this->balance_adjustment * -1;
|
||||
// $client->save();
|
||||
|
||||
// 06-09-2022
|
||||
$this->invoice
|
||||
|
@ -128,7 +128,7 @@ class Helpers
|
||||
|
||||
if(!$string_hit)
|
||||
return $value;
|
||||
// 04-10-2022 Return Early if no reserved keywords are present, this is a very expenseive process
|
||||
// 04-10-2022 Return Early if no reserved keywords are present, this is a very expensive process
|
||||
|
||||
Carbon::setLocale($entity->locale());
|
||||
|
||||
@ -296,8 +296,7 @@ class Helpers
|
||||
}
|
||||
|
||||
return $value;
|
||||
// $x = str_replace(["\n", "<br>"], ["\r", "<br>"], $value);
|
||||
// return $x;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,7 +65,17 @@ trait ClientGroupSettingsSaver
|
||||
}
|
||||
|
||||
$entity->settings = $entity_settings;
|
||||
$entity->save();
|
||||
|
||||
try{
|
||||
$entity->save();
|
||||
}
|
||||
catch(\Exception $e){
|
||||
|
||||
nlog("client settings failure");
|
||||
nlog($entity_settings);
|
||||
nlog($e->getMessage());
|
||||
|
||||
}
|
||||
|
||||
return $entity_settings;
|
||||
}
|
||||
|
@ -79,6 +79,19 @@ return [
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
'r2' => [
|
||||
'driver' => 's3',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION'),
|
||||
'bucket' => env('AWS_BUCKET'),
|
||||
'url' => env('AWS_URL'),
|
||||
'visibility' => 'private',
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
|
||||
'throw' => false,
|
||||
],
|
||||
|
||||
'gcs' => [
|
||||
'driver' => 'gcs',
|
||||
'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
|
||||
|
@ -166,11 +166,12 @@ class RecurringInvoiceTest extends TestCase
|
||||
'company_id' => $this->company->id,
|
||||
]);
|
||||
});
|
||||
$client = Client::all()->first();
|
||||
|
||||
$client = Client::query()->orderBy('id', 'DESC')->first();
|
||||
|
||||
RecurringInvoice::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
|
||||
|
||||
$RecurringInvoice = RecurringInvoice::where('user_id', $this->user->id)->first();
|
||||
$RecurringInvoice = RecurringInvoice::query()->where('user_id', $this->user->id)->orderBy('id', 'DESC')->first();
|
||||
$RecurringInvoice->save();
|
||||
|
||||
$response = $this->withHeaders([
|
||||
|
@ -63,7 +63,7 @@ class RecurringQuoteTest extends TestCase
|
||||
{
|
||||
RecurringQuote::factory()->create(['user_id' => $this->user->id, 'company_id' => $this->company->id, 'client_id' => $this->client->id]);
|
||||
|
||||
$RecurringQuote = RecurringQuote::where('user_id', $this->user->id)->first();
|
||||
$RecurringQuote = RecurringQuote::query()->where('user_id', $this->user->id)->orderBy('id','DESC')->first();
|
||||
$RecurringQuote->save();
|
||||
|
||||
$response = $this->withHeaders([
|
||||
|
@ -58,37 +58,5 @@ class DownloadHistoricalInvoiceTest extends TestCase
|
||||
$this->assertNotNull($this->invoice->activities);
|
||||
}
|
||||
|
||||
public function testBackupExists()
|
||||
{
|
||||
$this->mockActivity();
|
||||
|
||||
$this->assertNotNull($this->invoice->activities->first()->backup->html_backup);
|
||||
}
|
||||
|
||||
public function testBackupDownload()
|
||||
{
|
||||
$this->mockActivity();
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/activities/download_entity/'.$this->encodePrimaryKey($this->invoice->activities->first()->id));
|
||||
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function testBackupCheckPriorToDownloadWorks()
|
||||
{
|
||||
$this->mockActivity();
|
||||
|
||||
$backup = $this->invoice->activities->first()->backup;
|
||||
$backup->forceDelete();
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->get('/api/v1/activities/download_entity/'.$this->encodePrimaryKey($this->invoice->activities->first()->id));
|
||||
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user