-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dispose of result faster when fetchRow() is used on PooledResult
- Loading branch information
Showing
6 changed files
with
137 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Amp\Sql\Common\Test\Stub; | ||
|
||
use Amp\Sql\Common\PooledResult; | ||
use Amp\Sql\Result; | ||
|
||
final class StubPooledResult extends PooledResult | ||
{ | ||
protected static function newInstanceFrom(Result $result, \Closure $release): self | ||
{ | ||
return new self($result, $release); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Amp\Sql\Common\Test\Stub; | ||
|
||
use Amp\Sql\Result; | ||
|
||
final class StubResult implements Result, \IteratorAggregate | ||
{ | ||
private readonly array $rows; | ||
|
||
private int $current = 0; | ||
|
||
public function __construct(array $rows, private readonly ?Result $next = null) | ||
{ | ||
$this->rows = \array_values($rows); | ||
} | ||
|
||
public function getIterator(): \Iterator | ||
{ | ||
yield from $this->rows; | ||
} | ||
|
||
public function fetchRow(): ?array | ||
{ | ||
return $this->rows[$this->current++] ?? null; | ||
} | ||
|
||
public function getNextResult(): ?Result | ||
{ | ||
return $this->next; | ||
} | ||
|
||
public function getRowCount(): ?int | ||
{ | ||
return \count($this->rows); | ||
} | ||
|
||
public function getColumnCount(): ?int | ||
{ | ||
return null; | ||
} | ||
} |