Reduced query count for tag retrieval

This commit is contained in:
Marcin Kurczewski 2014-10-04 13:28:18 +02:00
parent 332ca8e4b7
commit 4220a83589

View file

@ -24,13 +24,17 @@ class TagDao extends AbstractDao implements ICrudDao
public function findByPostId($postId) public function findByPostId($postId)
{ {
$query = $this->fpdo->from('postTags')->where('postId', $postId); return $this->findByPostIds([$postId]);
$tagIds = array_map(function($arrayEntity) }
public function findByPostIds($postIds)
{ {
return $arrayEntity['tagId']; $query = $this->fpdo->from($this->tableName)
}, ->disableSmartJoin()
iterator_to_array($query)); ->innerJoin('postTags ON postTags.tagId = tags.id')
return $this->findByIds($tagIds); ->where('postTags.postId', $postIds);
$arrayEntities = iterator_to_array($query);
return $this->arrayToEntities($arrayEntities);
} }
public function exportJson() public function exportJson()