Get rid of unneeded sql queries
This commit is contained in:
@@ -46,30 +46,35 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
|
||||
* @param bool $withAcl
|
||||
* @return \OCP\AppFramework\Db\Entity if not found
|
||||
*/
|
||||
public function find($id, $withLabels=false, $withAcl=false) {
|
||||
public function find($id, $withLabels = false, $withAcl = false) {
|
||||
$sql = 'SELECT id, title, owner, color, archived FROM `*PREFIX*deck_boards` ' .
|
||||
'WHERE `id` = ?';
|
||||
$board = $this->findEntity($sql, [$id]);
|
||||
|
||||
// Add labels
|
||||
if ($withLabels) {
|
||||
$labels = $this->labelMapper->findAll($id);
|
||||
$board->setLabels($labels);
|
||||
}
|
||||
|
||||
// Add acl
|
||||
if ($withAcl) {
|
||||
$acl = $this->aclMapper->findAll($id);
|
||||
$board->setAcl($acl);
|
||||
}
|
||||
|
||||
return $board;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all boards for a given user
|
||||
*
|
||||
* @param $userId
|
||||
* @param null $limit
|
||||
* @param null $offset
|
||||
* @return array
|
||||
*/
|
||||
public function findAllByUser($userId, $limit=null, $offset=null) {
|
||||
public function findAllByUser($userId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT id, title, owner, color, archived, 0 as shared FROM oc_deck_boards WHERE owner = ? UNION ' .
|
||||
'SELECT boards.id, title, owner, color, archived, 1 as shared FROM oc_deck_boards as boards ' .
|
||||
'JOIN oc_deck_board_acl as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=\'user\' AND boards.owner != ?';
|
||||
@@ -91,15 +96,15 @@ class BoardMapper extends DeckMapper implements IPermissionMapper {
|
||||
* @param null $offset
|
||||
* @return array
|
||||
*/
|
||||
public function findAllByGroups($userId, $groups, $limit=null, $offset=null) {
|
||||
if(count($groups)<=0) {
|
||||
public function findAllByGroups($userId, $groups, $limit = null, $offset = null) {
|
||||
if (count($groups) <= 0) {
|
||||
return [];
|
||||
}
|
||||
$sql = 'SELECT boards.id, title, owner, color, archived, 2 as shared FROM oc_deck_boards as boards ' .
|
||||
'INNER JOIN oc_deck_board_acl as acl ON boards.id=acl.board_id WHERE owner != ? AND type=\'group\' AND (';
|
||||
for($i=0;$i<count($groups);$i++) {
|
||||
for ($i = 0; $i < count($groups); $i++) {
|
||||
$sql .= 'acl.participant = ? ';
|
||||
if(count($groups)>1 && $i<count($groups)-1) {
|
||||
if (count($groups) > 1 && $i < count($groups) - 1) {
|
||||
$sql .= ' OR ';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class CardService {
|
||||
$this->cardMapper->update($card);
|
||||
}
|
||||
// FIXME: return reordered cards without an additional db query
|
||||
//$cards = $this->cardMapper->findAll($stackId);
|
||||
$cards = $this->cardMapper->findAll($stackId);
|
||||
return $cards;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user