Fixed memory leak for join queries in hyperf/database. (#3222)

* Fix join clause memory leak

* Update CHANGELOG-2.0.md

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
tegic 2021-01-28 11:36:17 +08:00 committed by GitHub
parent 0acc0f1834
commit b8eb394d95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 12 deletions

View File

@ -5,6 +5,7 @@
- [#3047](https://github.com/hyperf/hyperf/pull/3047) Fixed bug that renew sid in all namespaces failed.
- [#3087](https://github.com/hyperf/hyperf/pull/3087) Fixed memory leak when using pipeline sometimes.
- [#3179](https://github.com/hyperf/hyperf/pull/3179) Fixed json-rpc client failed to receive data when the target server restart.
- [#3222](https://github.com/hyperf/hyperf/pull/3222) Fixed memory leak for join queries in `hyperf/database`.
# v2.0.25 - 2020-12-28

View File

@ -30,16 +30,36 @@ class JoinClause extends Builder
public $table;
/**
* The parent query builder instance.
* The connection of the parent query builder.
*
* @var \Hyperf\Database\Query\Builder
* @var \Hyperf\Database\ConnectionInterface
*/
private $parentQuery;
protected $parentConnection;
/**
* The grammar of the parent query builder.
*
* @var \Hyperf\Database\Query\Grammars\Grammar
*/
protected $parentGrammar;
/**
* The processor of the parent query builder.
*
* @var \Hyperf\Database\Query\Processors\Processor
*/
protected $parentProcessor;
/**
* The class name of the parent query builder.
*
* @var string
*/
protected $parentClass;
/**
* Create a new join clause instance.
*
* @param \Hyperf\Database\Query\Builder $parentQuery
* @param string $type
* @param string $table
*/
@ -47,12 +67,15 @@ class JoinClause extends Builder
{
$this->type = $type;
$this->table = $table;
$this->parentQuery = $parentQuery;
$this->parentClass = get_class($parentQuery);
$this->parentGrammar = $parentQuery->getGrammar();
$this->parentProcessor = $parentQuery->getProcessor();
$this->parentConnection = $parentQuery->getConnection();
parent::__construct(
$parentQuery->getConnection(),
$parentQuery->getGrammar(),
$parentQuery->getProcessor()
$this->parentConnection,
$this->parentGrammar,
$this->parentProcessor
);
}
@ -70,7 +93,7 @@ class JoinClause extends Builder
*
* @param \Closure|string $first
* @param null|string $operator
* @param null|string $second
* @param null|\Hyperf\Database\Query\Expression|string $second
* @param string $boolean
* @throws \InvalidArgumentException
* @return $this
@ -104,7 +127,7 @@ class JoinClause extends Builder
*/
public function newQuery()
{
return new static($this->parentQuery, $this->type, $this->table);
return new static($this->newParentQuery(), $this->type, $this->table);
}
/**
@ -114,6 +137,18 @@ class JoinClause extends Builder
*/
protected function forSubQuery()
{
return $this->parentQuery->newQuery();
return $this->newParentQuery()->newQuery();
}
}
/**
* Create a new parent query instance.
*
* @return \Hyperf\Database\Query\Builder
*/
protected function newParentQuery()
{
$class = $this->parentClass;
return new $class($this->parentConnection, $this->parentGrammar, $this->parentProcessor);
}
}