Merge pull request #21068 from nextcloud/backport/20776/stable19
[stable19] Improve group queries
This commit is contained in:
commit
3bf0285840
|
@ -118,7 +118,10 @@ class Database extends ABackend implements
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to cache
|
// Add to cache
|
||||||
$this->groupCache[$gid] = $gid;
|
$this->groupCache[$gid] = [
|
||||||
|
'gid' => $gid,
|
||||||
|
'displayname' => $gid
|
||||||
|
];
|
||||||
|
|
||||||
return $result === 1;
|
return $result === 1;
|
||||||
}
|
}
|
||||||
|
@ -244,15 +247,19 @@ class Database extends ABackend implements
|
||||||
|
|
||||||
// No magic!
|
// No magic!
|
||||||
$qb = $this->dbConn->getQueryBuilder();
|
$qb = $this->dbConn->getQueryBuilder();
|
||||||
$cursor = $qb->select('gid')
|
$cursor = $qb->select('gu.gid', 'g.displayname')
|
||||||
->from('group_user')
|
->from('group_user', 'gu')
|
||||||
|
->leftJoin('gu', 'groups', 'g', $qb->expr()->eq('gu.gid', 'g.gid'))
|
||||||
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
|
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
$groups = [];
|
$groups = [];
|
||||||
while ($row = $cursor->fetch()) {
|
while ($row = $cursor->fetch()) {
|
||||||
$groups[] = $row['gid'];
|
$groups[] = $row['gid'];
|
||||||
$this->groupCache[$row['gid']] = $row['gid'];
|
$this->groupCache[$row['gid']] = [
|
||||||
|
'gid' => $row['gid'],
|
||||||
|
'displayname' => $row['displayname'],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
$cursor->closeCursor();
|
$cursor->closeCursor();
|
||||||
|
|
||||||
|
@ -309,7 +316,7 @@ class Database extends ABackend implements
|
||||||
}
|
}
|
||||||
|
|
||||||
$qb = $this->dbConn->getQueryBuilder();
|
$qb = $this->dbConn->getQueryBuilder();
|
||||||
$cursor = $qb->select('gid')
|
$cursor = $qb->select('gid', 'displayname')
|
||||||
->from('groups')
|
->from('groups')
|
||||||
->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
|
->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
|
||||||
->execute();
|
->execute();
|
||||||
|
@ -317,7 +324,10 @@ class Database extends ABackend implements
|
||||||
$cursor->closeCursor();
|
$cursor->closeCursor();
|
||||||
|
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
$this->groupCache[$gid] = $gid;
|
$this->groupCache[$gid] = [
|
||||||
|
'gid' => $gid,
|
||||||
|
'displayname' => $result['displayname'],
|
||||||
|
];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -430,6 +440,10 @@ class Database extends ABackend implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDisplayName(string $gid): string {
|
public function getDisplayName(string $gid): string {
|
||||||
|
if (isset($this->groupCache[$gid])) {
|
||||||
|
return $this->groupCache[$gid]['displayname'];
|
||||||
|
}
|
||||||
|
|
||||||
$this->fixDI();
|
$this->fixDI();
|
||||||
|
|
||||||
$query = $this->dbConn->getQueryBuilder();
|
$query = $this->dbConn->getQueryBuilder();
|
||||||
|
|
Loading…
Reference in New Issue