1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Performance improvements removing unpaid gateway fees

This commit is contained in:
David Bomba 2021-10-25 07:25:14 +11:00
parent 84feb72e9e
commit e22967f10d
3 changed files with 23 additions and 3 deletions

View File

@ -52,6 +52,7 @@ class Handler extends ExceptionHandler
MaxAttemptsExceededException::class,
CommandNotFoundException::class,
ValidationException::class,
ModelNotFoundException::class,
];
/**

View File

@ -339,6 +339,10 @@ class InvoiceService
public function removeUnpaidGatewayFees()
{
//return early if type three does not exist.
if(!collect($this->invoice->line_items)->contains('type_id', 3))
return $this;
$this->invoice->line_items = collect($this->invoice->line_items)
->reject(function ($item) {
return $item->type_id == '3';

View File

@ -10,6 +10,7 @@
*/
namespace Tests\Unit;
use App\Factory\InvoiceItemFactory;
use App\Utils\Traits\UserSessionAttributes;
use Illuminate\Support\Facades\Session;
use Tests\TestCase;
@ -19,13 +20,10 @@ use Tests\TestCase;
*/
class CollectionMergingTest extends TestCase
{
use UserSessionAttributes;
public function setUp() :void
{
parent::setUp();
Session::start();
}
public function testUniqueValues()
@ -62,4 +60,21 @@ class CollectionMergingTest extends TestCase
$intersect = $collection->intersectByKeys($collection->flatten(1)->unique());
$this->assertEquals(11, $intersect->count());
}
public function testExistenceInCollection()
{
$items = InvoiceItemFactory::generate(5);
$this->assertFalse(collect($items)->contains('type_id', "3"));
$this->assertFalse(collect($items)->contains('type_id', 3));
$item = InvoiceItemFactory::create();
$item->type_id = "3";
$items[] = $item;
$this->assertTrue(collect($items)->contains('type_id', "3"));
$this->assertTrue(collect($items)->contains('type_id', 3));
}
}