diff options
author | emkael <emkael@tlen.pl> | 2016-05-07 20:33:10 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-05-09 12:37:59 +0200 |
commit | 267d16fe0bf60b85a44390ff99b57bca67c2d616 (patch) | |
tree | ce46fb0cb56501906c54b5c297fbac7f267aab98 /app/php/facades | |
parent | 640538e18581fb260997b0e84f131eda2b67c98f (diff) |
* caching Calendar records by custom URL
Diffstat (limited to 'app/php/facades')
-rw-r--r-- | app/php/facades/CalendarFacade.php | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/app/php/facades/CalendarFacade.php b/app/php/facades/CalendarFacade.php index 232acf3..b15eac3 100644 --- a/app/php/facades/CalendarFacade.php +++ b/app/php/facades/CalendarFacade.php @@ -135,7 +135,11 @@ class CalendarFacade extends Facade { } public function getAll() { - return Calendar::finder()->withCategory()->findAll('ORDER BY name ASC'); + $records = Calendar::finder()->withCategory()->findAll('ORDER BY name ASC'); + foreach ($records as $record) { + $this->_fillUrlCache($record); + } + return $records; } public function getCategories() { @@ -143,15 +147,36 @@ class CalendarFacade extends Facade { } public function get($uid) { - return Calendar::finder()->withCategory()->findAllByPks($uid); + $records = Calendar::finder()->withCategory()->findAllByPks($uid); + foreach ($records as $record) { + $this->_fillUrlCache($record); + } + return $records; + } + + private $_urlCache = []; + private function _fillUrlCache($record) { + if ($record && $record->CustomUrl + && !isset($this->_urlCache[$record->CustomUrl])) { + $dto = new CalendarDTO(); + if ($record) { + $dto->loadRecord($record); + } else { + $dto = NULL; + } + return $this->_urlCache[$record->CustomUrl] = $dto; + } } public function resolveUrl($url) { - $dto = new CalendarDTO(); - $record = Calendar::finder()->findByCustomUrl($url); - if ($record) { - $dto->loadRecord($record); - return $dto; + if ($url) { + if (isset($this->_urlCache[$url])) { + return $this->_urlCache[$url]; + } + $record = Calendar::finder()->findByCustomUrl($url); + if ($record) { + return $this->_fillUrlCache($record); + } } return NULL; } |