summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorblizzz <blizzz@arthur-schiwon.de>2019-01-03 17:08:52 +0100
committerGitHub <noreply@github.com>2019-01-03 17:08:52 +0100
commitaad32771f8f4eaa8684fee049cc3ce91be139608 (patch)
treed9b02db3d8d1bc073c86005962acf3396bb0e2ad /lib
parent68952306aa3309286b6cd685976c2cdee674268a (diff)
parentf394bf356e6ce282659e9fe5ad3092453f5c31b1 (diff)
downloadnextcloud-server-aad32771f8f4eaa8684fee049cc3ce91be139608.tar.gz
nextcloud-server-aad32771f8f4eaa8684fee049cc3ce91be139608.zip
Merge pull request #13161 from nextcloud/perf/fix_comments_in_folder_function
Rewrite getNumberOfUnreadCommentsForFolder query
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Comments/Manager.php43
1 files changed, 29 insertions, 14 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php
index f3865c6504f..8df4a84a477 100644
--- a/lib/private/Comments/Manager.php
+++ b/lib/private/Comments/Manager.php
@@ -581,27 +581,42 @@ class Manager implements ICommentsManager {
* @param int $folderId
* @param IUser $user
* @return array [$fileId => $unreadCount]
+ *
+ * @suppress SqlInjectionChecker
*/
public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) {
$qb = $this->dbConn->getQueryBuilder();
+
$query = $qb->select('f.fileid')
->addSelect($qb->func()->count('c.id', 'num_ids'))
- ->from('comments', 'c')
- ->innerJoin('c', 'filecache', 'f', $qb->expr()->andX(
- $qb->expr()->eq('c.object_type', $qb->createNamedParameter('files')),
- $qb->expr()->eq('f.fileid', $qb->expr()->castColumn('c.object_id', IQueryBuilder::PARAM_INT))
+ ->from('filecache', 'f')
+ ->leftJoin('f', 'comments', 'c', $qb->expr()->eq(
+ 'f.fileid', $qb->expr()->castColumn('c.object_id', IQueryBuilder::PARAM_INT)
))
- ->leftJoin('c', 'comments_read_markers', 'm', $qb->expr()->andX(
- $qb->expr()->eq('m.object_type', $qb->createNamedParameter('files')),
- $qb->expr()->eq('m.object_id', 'c.object_id'),
- $qb->expr()->eq('m.user_id', $qb->createNamedParameter($user->getUID()))
+ ->leftJoin('c', 'comments_read_markers', 'm', $qb->expr()->eq(
+ 'c.object_id', 'm.object_id'
))
- ->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($folderId)))
- ->andWhere($qb->expr()->orX(
- $qb->expr()->gt('c.creation_timestamp', 'marker_datetime'),
- $qb->expr()->isNull('marker_datetime')
- ))
- ->groupBy('f.fileid');
+ ->where(
+ $qb->expr()->andX(
+ $qb->expr()->eq('f.parent', $qb->createNamedParameter($folderId)),
+ $qb->expr()->orX(
+ $qb->expr()->eq('c.object_type', $qb->createNamedParameter('files')),
+ $qb->expr()->isNull('c.object_type')
+ ),
+ $qb->expr()->orX(
+ $qb->expr()->eq('m.object_type', $qb->createNamedParameter('files')),
+ $qb->expr()->isNull('m.object_type')
+ ),
+ $qb->expr()->orX(
+ $qb->expr()->eq('m.user_id', $qb->createNamedParameter($user->getUID())),
+ $qb->expr()->isNull('m.user_id')
+ ),
+ $qb->expr()->orX(
+ $qb->expr()->gt('c.creation_timestamp', 'm.marker_datetime'),
+ $qb->expr()->isNull('m.marker_datetime')
+ )
+ )
+ )->groupBy('f.fileid');
$resultStatement = $query->execute();