Skip to content
Snippets Groups Projects
Commit c4bebf66 authored by Joas Schilling's avatar Joas Schilling
Browse files

Do not count the entries when we only need to know if it is at least one

parent aa1a0a15
No related branches found
No related tags found
No related merge requests found
......@@ -172,23 +172,32 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
$this->assertTagsExist([$tagId]);
$query = $this->connection->getQueryBuilder();
$query->select($query->createFunction('COUNT(1)'))
->from(self::RELATION_TABLE)
if (!$all) {
// If we only need one entry, we make the query lighter, by not
// counting the elements
$query->select('*')
->setMaxResults(1);
} else {
$query->select($query->createFunction('COUNT(1)'));
}
$query->from(self::RELATION_TABLE)
->where($query->expr()->in('objectid', $query->createParameter('objectids')))
->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype')))
->andWhere($query->expr()->eq('systemtagid', $query->createParameter('tagid')))
->setParameter('objectids', $objIds, Connection::PARAM_INT_ARRAY)
->setParameter('tagid', $tagId)
->setParameter('objecttype', $objectType)
->setMaxResults(1);
->setParameter('objecttype', $objectType);
$result = $query->execute();
$row = $result->fetch(\PDO::FETCH_NUM);
$result->closeCursor();
if ($all) {
return ((int)$row[0] === count($objIds));
} else {
return (int)$row[0] > 0;
return (bool) $row;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment