diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-08-17 12:28:24 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-08-17 12:28:24 +0300 |
commit | eb6546838279b9c3dfae64848b3523b5a3137ebd (patch) | |
tree | a6e4e8902881fdda0eb21ec14ea524bf5279e86d /lib | |
parent | ab48cccefc8a225cc32a2ef4c9cb08cafb5f95e9 (diff) |
Avoid querying each card when getting the calendars only
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/DAV/Calendar.php | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/DAV/Calendar.php b/lib/DAV/Calendar.php index 6e73999a..7e02013b 100644 --- a/lib/DAV/Calendar.php +++ b/lib/DAV/Calendar.php @@ -52,12 +52,6 @@ class Calendar extends ExternalCalendar { $this->board = $board; $this->principalUri = $principalUri; - - if ($board) { - $this->children = $this->backend->getChildren($board->getId()); - } else { - $this->children = []; - } } public function getOwner() { @@ -122,7 +116,7 @@ class Calendar extends ExternalCalendar { public function getChild($name) { if ($this->childExists($name)) { $card = array_values(array_filter( - $this->children, + $this->getBackendChildren(), function ($card) use (&$name) { return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics' === $name; } @@ -137,7 +131,7 @@ class Calendar extends ExternalCalendar { public function getChildren() { $childNames = array_map(function ($card) { return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics'; - }, $this->children); + }, $this->getBackendChildren()); $children = []; @@ -148,9 +142,23 @@ class Calendar extends ExternalCalendar { 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) { return count(array_filter( - $this->children, + $this->getBackendChildren(), function ($card) use (&$name) { return $card->getCalendarPrefix() . '-' . $card->getId() . '.ics' === $name; } |