-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delay load pages #257
Delay load pages #257
Conversation
nice approach for #256 |
loading works for any templating plugin.
@@ -171,7 +119,7 @@ public function getPageOffset(\Phile\Model\Page $page, $offset = 0) { | |||
* | |||
* @return mixed|\Phile\Model\Page | |||
*/ | |||
protected function getPage($filePath, $folder = CONTENT_DIR) { | |||
public function getPage($filePath, $folder = CONTENT_DIR) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should try to keep that protected. Users are supposed to call findByPath
.
I'm 👍 on the idea and in principal I'm OKish with the implementation. But of course I'm having a small "but" and here it comes. 😉 What's a little bit uncomfortable is to split the worker code of I suggest we use a proxy-pattern for lazy-loading and subclass PageCollection from Repository\Page and keep In Repository\Page: class Page {
public function findAll(array $options = array(), $folder = CONTENT_DIR) {
return new PageProxy($options, $folder);
}
protected function _findAll(array $options = array(), $folder) {
// ... existing code
} A $folder setter in the constructor needs to be implemented, but imho that's not bad thing to have anyway. Then use the simple PageCollection from the PR's first commit just as proxy extending Page: class PageProxy extends Page implements \ArrayAccess, \IteratorAggregate {
// ...
private function load() {
if ($this->pages === null) {
$this->pages = parent::_findAll($this->options, $this->folder);
}
} With that But that's purely academical at the moment. Overall and practically a 👍 from me. |
I was not thrilled with the code separation initially either. I will give the proxy method a shot, that sounds like a good approach. |
Collection class accepts a callback function which will be executed when the pages need to be loaded. This allows for minimal changes to the existing repository class and keeps the search code where it belongs.
I think we can run with that. 👍 |
merged into develop in 62496b5 |
Delays scanning the content directory for pages until the pages variable is used. Speeds up loading time if the variable is not required.