mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Improve memory handling
This commit is contained in:
parent
de8761f519
commit
dddfd32757
@ -224,7 +224,9 @@ class CreateEntityPdf implements ShouldQueue
|
||||
$this->company = null;
|
||||
$this->client = null;
|
||||
$this->contact = null;
|
||||
|
||||
$maker = null;
|
||||
$state = null;
|
||||
|
||||
return $file_path;
|
||||
}
|
||||
|
||||
|
@ -200,6 +200,8 @@ class CreateRawPdf implements ShouldQueue
|
||||
}
|
||||
|
||||
if ($pdf) {
|
||||
$maker =null;
|
||||
$state = null;
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
|
@ -131,6 +131,14 @@ class EmailEntity implements ShouldQueue
|
||||
|
||||
$nmo = null;
|
||||
$this->invitation = null;
|
||||
$this->company = null;
|
||||
$this->entity_string = null;
|
||||
$this->entity = null;
|
||||
$this->settings = null;
|
||||
$this->reminder_template = null;
|
||||
$this->html_engine = null;
|
||||
$this->template_data = null;
|
||||
$this->email_entity_builder = null;
|
||||
}
|
||||
|
||||
private function resolveEntityString() :string
|
||||
|
@ -129,9 +129,13 @@ class NinjaMailerJob implements ShouldQueue
|
||||
LightLogs::create(new EmailSuccess($this->nmo->company->company_key))
|
||||
->send();
|
||||
|
||||
|
||||
nlog('Using ' . ((int) (memory_get_usage(true) / (1024 * 1024))) . 'MB ');
|
||||
|
||||
$this->nmo = null;
|
||||
$this->company = null;
|
||||
|
||||
gc_collect_cycles();
|
||||
|
||||
} catch (\Exception | \RuntimeException | \Google\Service\Exception $e) {
|
||||
|
||||
nlog("error failed with {$e->getMessage()}");
|
||||
@ -169,7 +173,16 @@ class NinjaMailerJob implements ShouldQueue
|
||||
/* Don't send postmark failures to Sentry */
|
||||
if(Ninja::isHosted() && (!$e instanceof ClientException))
|
||||
app('sentry')->captureException($e);
|
||||
|
||||
$message = null;
|
||||
$this->nmo = null;
|
||||
$this->company = null;
|
||||
gc_collect_cycles();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Switch statement to handle failure notifications */
|
||||
@ -191,6 +204,7 @@ class NinjaMailerJob implements ShouldQueue
|
||||
|
||||
if ($this->nmo->to_user instanceof ClientContact)
|
||||
$this->logMailError($message, $this->nmo->to_user->client);
|
||||
|
||||
}
|
||||
|
||||
private function setMailDriver()
|
||||
|
3
app/Jobs/Vendor/CreatePurchaseOrderPdf.php
vendored
3
app/Jobs/Vendor/CreatePurchaseOrderPdf.php
vendored
@ -213,6 +213,9 @@ class CreatePurchaseOrderPdf implements ShouldQueue
|
||||
info($maker->getCompiledHTML());
|
||||
}
|
||||
|
||||
$maker = null;
|
||||
$state = null;
|
||||
|
||||
return $pdf;
|
||||
|
||||
}
|
||||
|
@ -515,17 +515,10 @@ class MultiDB
|
||||
{
|
||||
/* This will set the database connection for the request */
|
||||
config(['database.default' => $database]);
|
||||
|
||||
// for some reason this breaks everything _hard_
|
||||
// DB::purge($database);
|
||||
// DB::reconnect($database);
|
||||
}
|
||||
|
||||
public static function setDefaultDatabase()
|
||||
{
|
||||
config(['database.default' => config('ninja.db.default')]);
|
||||
|
||||
// DB::purge(config('ninja.db.default'));
|
||||
// DB::reconnect(config('ninja.db.default'));
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class ActivityRepository extends BaseRepository
|
||||
$activity->save();
|
||||
|
||||
//rate limiter
|
||||
// $this->createBackup($entity, $activity);
|
||||
$this->createBackup($entity, $activity);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,8 +167,13 @@ class ActivityRepository extends BaseRepository
|
||||
|
||||
$maker = new PdfMakerService($state);
|
||||
|
||||
return $maker->design($template)
|
||||
$html = $maker->design($template)
|
||||
->build()
|
||||
->getCompiledHTML(true);
|
||||
|
||||
$maker = null;
|
||||
$state = null;
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
@ -108,6 +108,9 @@ class Statement
|
||||
\DB::connection(config('database.default'))->rollBack();
|
||||
}
|
||||
|
||||
$maker = null;
|
||||
$state = null;
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
|
@ -107,6 +107,9 @@ class GenerateDeliveryNote
|
||||
|
||||
Storage::disk($this->disk)->put($file_path, $pdf);
|
||||
|
||||
$maker = null;
|
||||
$state = null;
|
||||
|
||||
return $file_path;
|
||||
}
|
||||
}
|
||||
|
@ -712,6 +712,8 @@ class Design extends BaseDesign
|
||||
$elements[] = $element;
|
||||
}
|
||||
|
||||
$document = null;
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
|
@ -234,44 +234,11 @@ trait DesignHelpers
|
||||
});
|
||||
";
|
||||
|
||||
// Unminified version, just for the reference.
|
||||
// By default all table headers are hidden with HTML `hidden` property.
|
||||
// This will check for table data values & if they're not empty it will remove hidden from the column itself.
|
||||
|
||||
/*
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.querySelectorAll("#product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(e => {
|
||||
if ("" !== e.innerText) {
|
||||
let t = e.getAttribute("data-ref").slice(0, -3);
|
||||
document.querySelector(`th[data-ref="${t}-th"]`).removeAttribute("hidden");
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelectorAll("#product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(e => {
|
||||
let t = e.getAttribute("data-ref").slice(0, -3);
|
||||
t = document.querySelector(`th[data-ref="${t}-th"]`);
|
||||
|
||||
if (!t.hasAttribute('hidden')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ("" == e.innerText) {
|
||||
e.setAttribute('hidden', 'true');
|
||||
}
|
||||
});
|
||||
}, false);
|
||||
*/
|
||||
|
||||
$javascript = 'document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll("#product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(t=>{if(""!==t.innerText){let e=t.getAttribute("data-ref").slice(0,-3);document.querySelector(`th[data-ref="${e}-th"]`).removeAttribute("hidden")}}),document.querySelectorAll("#product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(t=>{let e=t.getAttribute("data-ref").slice(0,-3);(e=document.querySelector(`th[data-ref="${e}-th"]`)).hasAttribute("hidden")&&""==t.innerText&&t.setAttribute("hidden","true")})},!1);';
|
||||
|
||||
// Previously we've been decoding the HTML on the backend and XML parsing isn't good options because it requires,
|
||||
// strict & valid HTML to even output/decode. Decoding is now done on the frontend with this piece of Javascript.
|
||||
|
||||
/**
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.querySelectorAll(`[data-state="encoded-html"]`).forEach((element) => element.innerHTML = element.innerText)
|
||||
}, false);
|
||||
*/
|
||||
$html_decode = 'document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(`[data-state="encoded-html"]`).forEach(e=>e.innerHTML=e.innerText)},!1);';
|
||||
|
||||
return ['element' => 'div', 'elements' => [
|
||||
@ -391,17 +358,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
return $converter->convert($markdown);
|
||||
}
|
||||
|
||||
// public function processMarkdownOnLineItems(array &$items): void
|
||||
// {
|
||||
// foreach ($items as $key => $item) {
|
||||
// foreach ($item as $variable => $value) {
|
||||
// $item[$variable] = DesignHelpers::parseMarkdownToHtml($value ?? '');
|
||||
// }
|
||||
|
||||
// $items[$key] = $item;
|
||||
// }
|
||||
// }
|
||||
|
||||
public function processNewLines(array &$items): void
|
||||
{
|
||||
foreach ($items as $key => $item) {
|
||||
|
@ -895,6 +895,10 @@ html {
|
||||
|
||||
$dom->appendChild($container);
|
||||
|
||||
return $dom->saveHTML();
|
||||
$html = $dom->saveHTML();
|
||||
|
||||
$dom = null;
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
@ -137,6 +137,8 @@ class Number
|
||||
public static function formatMoney($value, $entity) :string
|
||||
{
|
||||
|
||||
$value = floatval($value);
|
||||
|
||||
$currency = $entity->currency();
|
||||
|
||||
$thousand = $currency->thousand_separator;
|
||||
|
Loading…
Reference in New Issue
Block a user