Avoid querying each card when getting the calendars only

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2022-08-17 11:28:24 +02:00
committed by backportbot-nextcloud[bot]
parent b99fb6e8f6
commit a4e6c7b746

View File

@@ -52,12 +52,6 @@ class Calendar extends ExternalCalendar {
$this->board = $board; $this->board = $board;
$this->principalUri = $principalUri; $this->principalUri = $principalUri;
if ($board) {
$this->children = $this->backend->getChildren($board->getId());
} else {
$this->children = [];
}
} }
public function getOwner() { public function getOwner() {
@@ -122,7 +116,7 @@ class Calendar extends ExternalCalendar {
public function getChild($name) { public function getChild($name) {
if ($this->childExists($name)) { if ($this->childExists($name)) {
$card = array_values(array_filter( $card = array_values(array_filter(
$this->children, $this->getBackendChildren(),
function ($card) use (&$name) { function ($card) use (&$name) {
return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics' === $name; return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics' === $name;
} }
@@ -137,7 +131,7 @@ class Calendar extends ExternalCalendar {
public function getChildren() { public function getChildren() {
$childNames = array_map(function ($card) { $childNames = array_map(function ($card) {
return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics'; return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics';
}, $this->children); }, $this->getBackendChildren());
$children = []; $children = [];
@@ -148,9 +142,23 @@ class Calendar extends ExternalCalendar {
return $children; return $children;
} }
private function getBackendChildren() {
if ($this->children) {
return $this->children;
}
if ($this->board) {
$this->children = $this->backend->getChildren($this->board->getId());
} else {
$this->children = [];
}
return $this->children;
}
public function childExists($name) { public function childExists($name) {
return count(array_filter( return count(array_filter(
$this->children, $this->getBackendChildren(),
function ($card) use (&$name) { function ($card) use (&$name) {
return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics' === $name; return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics' === $name;
} }