mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 22:13:13 +00:00
Avoid N+1 in User_Query
This commit is contained in:
@@ -13,7 +13,6 @@ use Alchemy\Phrasea\Application;
|
|||||||
use Alchemy\Phrasea\Model\Entities\User;
|
use Alchemy\Phrasea\Model\Entities\User;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Alchemy\Phrasea\Utilities\Countries;
|
use Alchemy\Phrasea\Utilities\Countries;
|
||||||
use Doctrine\Common\Collections\Collection;
|
|
||||||
|
|
||||||
class User_Query implements User_QueryInterface
|
class User_Query implements User_QueryInterface
|
||||||
{
|
{
|
||||||
@@ -81,7 +80,7 @@ class User_Query implements User_QueryInterface
|
|||||||
/**
|
/**
|
||||||
* Return query results
|
* Return query results
|
||||||
*
|
*
|
||||||
* @return User[]|Collection
|
* @return User[]|\Doctrine\Common\Collections\Collection
|
||||||
*/
|
*/
|
||||||
public function get_results()
|
public function get_results()
|
||||||
{
|
{
|
||||||
@@ -257,13 +256,22 @@ class User_Query implements User_QueryInterface
|
|||||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
$users = new ArrayCollection();
|
$userIndexes = [];
|
||||||
|
|
||||||
foreach ($rs as $row) {
|
foreach ($rs as $index => $row) {
|
||||||
$users[] = $this->app['repo.users']->find($row['id']);
|
$userIndexes[$row['id']] = $index;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->results = $users;
|
$users = [];
|
||||||
|
|
||||||
|
/** @var User $user */
|
||||||
|
foreach ($this->app['repo.users']->findBy(['id' => array_keys($userIndexes)]) as $user) {
|
||||||
|
$users[$userIndexes[$user->getId()]] = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
ksort($users);
|
||||||
|
|
||||||
|
$this->results = new ArrayCollection($users);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user