summaryrefslogtreecommitdiffstats
path: root/lib/private/Group
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2020-05-01 20:02:16 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2020-05-02 10:13:37 +0200
commit5ebb53593c88966454879ce4aedbe4c337efaf40 (patch)
tree38b246df158fb9fcd7527b9dad97c0463e1fdde3 /lib/private/Group
parent24bb4a05c46069d459086a36cfc896d1f5b6915e (diff)
downloadnextcloud-server-5ebb53593c88966454879ce4aedbe4c337efaf40.tar.gz
nextcloud-server-5ebb53593c88966454879ce4aedbe4c337efaf40.zip
Improve group queries
Before we'd also get the diplayname for each group in the backend. In a separate query. This is of course not ideal as this information is obtained on each and every query. Now this is queried once and properly cached. Also added more caching to the manager. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Group')
-rw-r--r--lib/private/Group/Database.php26
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php
index 1202ba09b13..ec8f7ea6f53 100644
--- a/lib/private/Group/Database.php
+++ b/lib/private/Group/Database.php
@@ -118,7 +118,10 @@ class Database extends ABackend implements
}
// Add to cache
- $this->groupCache[$gid] = $gid;
+ $this->groupCache[$gid] = [
+ 'gid' => $gid,
+ 'displayname' => $gid
+ ];
return $result === 1;
}
@@ -244,15 +247,19 @@ class Database extends ABackend implements
// No magic!
$qb = $this->dbConn->getQueryBuilder();
- $cursor = $qb->select('gid')
- ->from('group_user')
+ $cursor = $qb->select('gu.gid', 'g.displayname')
+ ->from('group_user', 'gu')
+ ->leftJoin('gu', 'groups', 'g', $qb->expr()->eq('gu.gid', 'g.gid'))
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
->execute();
$groups = [];
while ($row = $cursor->fetch()) {
$groups[] = $row['gid'];
- $this->groupCache[$row['gid']] = $row['gid'];
+ $this->groupCache[$row['gid']] = [
+ 'gid' => $row['gid'],
+ 'displayname' => $row['displayname'],
+ ];
}
$cursor->closeCursor();
@@ -309,7 +316,7 @@ class Database extends ABackend implements
}
$qb = $this->dbConn->getQueryBuilder();
- $cursor = $qb->select('gid')
+ $cursor = $qb->select('gid', 'displayname')
->from('groups')
->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
->execute();
@@ -317,7 +324,10 @@ class Database extends ABackend implements
$cursor->closeCursor();
if ($result !== false) {
- $this->groupCache[$gid] = $gid;
+ $this->groupCache[$gid] = [
+ 'gid' => $gid,
+ 'displayname' => $result['displayname'],
+ ];
return true;
}
return false;
@@ -430,6 +440,10 @@ class Database extends ABackend implements
}
public function getDisplayName(string $gid): string {
+ if (isset($this->groupCache[$gid])) {
+ return $this->groupCache[$gid]['displayname'];
+ }
+
$this->fixDI();
$query = $this->dbConn->getQueryBuilder();