summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-05-07 20:33:10 +0200
committeremkael <emkael@tlen.pl>2016-05-09 12:37:59 +0200
commit267d16fe0bf60b85a44390ff99b57bca67c2d616 (patch)
treece46fb0cb56501906c54b5c297fbac7f267aab98
parent640538e18581fb260997b0e84f131eda2b67c98f (diff)
* caching Calendar records by custom URL
-rw-r--r--app/php/facades/CalendarFacade.php39
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;
}