mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for memory consumption with client statements
This commit is contained in:
parent
ada65baca0
commit
4091538161
@ -28,6 +28,7 @@ use App\Utils\Ninja;
|
||||
use App\Utils\Number;
|
||||
use App\Utils\PhantomJS\Phantom;
|
||||
use App\Utils\Traits\Pdf\PdfMaker as PdfMakerTrait;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\LazyCollection;
|
||||
@ -123,7 +124,7 @@ class Statement
|
||||
*/
|
||||
protected function setupEntity(): self
|
||||
{
|
||||
if (count($this->getInvoices()) >= 1) {
|
||||
if ($this->getInvoices()->count() >= 1) {
|
||||
$this->entity = $this->getInvoices()->first();
|
||||
}
|
||||
|
||||
@ -218,7 +219,7 @@ class Statement
|
||||
*
|
||||
* @return Invoice[]|\Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
protected function getInvoices(): LazyCollection
|
||||
protected function getInvoices(): Builder
|
||||
{
|
||||
return Invoice::withTrashed()
|
||||
->where('is_deleted', false)
|
||||
@ -226,8 +227,7 @@ class Statement
|
||||
->where('client_id', $this->client->id)
|
||||
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID])
|
||||
->whereBetween('date', [$this->options['start_date'], $this->options['end_date']])
|
||||
->orderBy('number', 'ASC')
|
||||
->cursor();
|
||||
->orderBy('number', 'ASC');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,7 +235,7 @@ class Statement
|
||||
*
|
||||
* @return Payment[]|\Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
protected function getPayments(): LazyCollection
|
||||
protected function getPayments(): Builder
|
||||
{
|
||||
return Payment::withTrashed()
|
||||
->with('client.country','invoices')
|
||||
@ -244,8 +244,7 @@ class Statement
|
||||
->where('client_id', $this->client->id)
|
||||
->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
|
||||
->whereBetween('date', [$this->options['start_date'], $this->options['end_date']])
|
||||
->orderBy('number', 'ASC')
|
||||
->cursor();
|
||||
->orderBy('number', 'ASC');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -359,7 +359,7 @@ class Design extends BaseDesign
|
||||
|
||||
$tbody = [];
|
||||
|
||||
foreach ($this->invoices as $invoice) {
|
||||
foreach ($this->invoices->cursor() as $invoice) {
|
||||
$element = ['element' => 'tr', 'elements' => []];
|
||||
|
||||
$element['elements'][] = ['element' => 'td', 'content' => $invoice->number];
|
||||
@ -407,7 +407,7 @@ class Design extends BaseDesign
|
||||
|
||||
$tbody = [];
|
||||
|
||||
foreach ($this->payments as $payment) {
|
||||
foreach ($this->payments->cursor() as $payment) {
|
||||
foreach ($payment->invoices as $invoice) {
|
||||
$element = ['element' => 'tr', 'elements' => []];
|
||||
|
||||
|
@ -41,7 +41,7 @@ trait DesignHelpers
|
||||
if (isset($this->context['invoices'])) {
|
||||
$this->invoices = $this->context['invoices'];
|
||||
|
||||
if (\count($this->invoices) >= 1) {
|
||||
if ($this->invoices->count() >= 1) {
|
||||
$this->entity = $this->invoices->first();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user