Reduced query count for tag retrieval
This commit is contained in:
parent
332ca8e4b7
commit
4220a83589
1 changed files with 11 additions and 7 deletions
|
@ -24,13 +24,17 @@ class TagDao extends AbstractDao implements ICrudDao
|
|||
|
||||
public function findByPostId($postId)
|
||||
{
|
||||
$query = $this->fpdo->from('postTags')->where('postId', $postId);
|
||||
$tagIds = array_map(function($arrayEntity)
|
||||
{
|
||||
return $arrayEntity['tagId'];
|
||||
},
|
||||
iterator_to_array($query));
|
||||
return $this->findByIds($tagIds);
|
||||
return $this->findByPostIds([$postId]);
|
||||
}
|
||||
|
||||
public function findByPostIds($postIds)
|
||||
{
|
||||
$query = $this->fpdo->from($this->tableName)
|
||||
->disableSmartJoin()
|
||||
->innerJoin('postTags ON postTags.tagId = tags.id')
|
||||
->where('postTags.postId', $postIds);
|
||||
$arrayEntities = iterator_to_array($query);
|
||||
return $this->arrayToEntities($arrayEntities);
|
||||
}
|
||||
|
||||
public function exportJson()
|
||||
|
|
Loading…
Reference in a new issue