Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

suggestion speed up autoid #7

Open
bnomei opened this issue Mar 9, 2017 · 2 comments
Open

suggestion speed up autoid #7

bnomei opened this issue Mar 9, 2017 · 2 comments

Comments

@bnomei
Copy link

bnomei commented Mar 9, 2017

hash
you could forward the $page->diruri() into getUniqueAutoId() and use it as an additional param to create the hash. it would be a pretty good unique and the very expensive check using site()->pages()->index() in getUniqueAutoIdcould be avoided.

id
why not write/read the latest value in an autoid-storage-file at /cache/? and only check for index if file is missing? that is certainly faster than site()->pages()->index() every time.

@bnomei
Copy link
Author

bnomei commented Mar 9, 2017

cached hash to file maps
instead of using site()->pages()->index() one could also cache the results to make it faster. that is when having al lot of pages and index() is slower than a file-read.

public static function getPageByAutoID($autoid) {
	$f = kirby()->roots()->cache().DS.'autoid-'.$autoid.'.txt';
	if(f::exists($f)) {
		$uri = f::read($f);
		if($page = page($uri)) {
			return $page;
		}
	}
	$pageCollection = site()->pages()->index()->filterBy(c::get('autoid.name', 'autoid'), $autoid);
	if($pageCollection->count() > 0) {
		$page = $pageCollection->first();
		f::write($f, $page->uri());
		return $page;
	}
	return null;
}

@Targoran
Copy link
Contributor

You are making a valid point, site()->pages()->index() is indeed quite slow on bigger sites. Will look into it soon!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants