Jump to content

Performance considerations -- find vs get, and routing


deltavik
 Share

Recommended Posts

Hey guys, 

I have two performance related questions. 

Question 1. find vs get

In my setup, I have a template called 'article,' which is a child of 'articles.' There are two ways to  get all articles.

This: 

$pages->get("/articles")->children;

or this: 

$pages->find("template=article");

And if I wanted to further filter the articles by author , the queries would look like these: 

$pages->get("/articles")->children("author=john");

and

$pages->find("template=article,author=john");

 

I think "get" would be faster in such situations. What are your thoughts? Are there any best coding practices for PW performance? 

Question 2: URL Routing

The article urls in my old site are in this format: http://domainname.com/article-url. 

But, in PW, the urls look like this: http://domainname.com/articles/article-url. 

For URL redirection, based on what I was able to find on the forums,  I made the homepage accept url segments. Then I route the requests based on the url segment (which essentially is the 'name' of the article page.) 

The question now is -- how big of performance hit will the site take due to this routing? Or am I needlessly thinking too much?

thanks,

 

 

Link to comment
Share on other sites

Quote

I think "get" would be faster in such situations. What are your thoughts? Are there any best coding practices for PW performance? 

Honestly it's probably not going to matter much here, so I'd say go with whatever is more readable to you. But since you asked: technically, if you can get something done with just one find/get operation rather than two, that's going to have an edge. Meaning, your single $pages->find("template=article,author=john"); is probably going to be the most efficient. But not likely in a way that's going to be measurable. 

Something to note is that both $pages->get() and $page->children() (and pretty much any method that returns pages from the DB) are simply front-end's to $pages->find() with certain assumptions placed on top of them.

Quote

 

For URL redirection, based on what I was able to find on the forums,  I made the homepage accept url segments. Then I route the requests based on the url segment (which essentially is the 'name' of the article page.) 

The question now is -- how big of performance hit will the site take due to this routing? Or am I needlessly thinking too much?

 

Not much of a performance hit, but you are right that it's not as efficient as just letting it load at the original URL. That's because behind-the-scenes your homepage is first being rendered (or at least its template is being called), and then another page is being rendered from it. If you don't want any compromises at all, even if small, then you could instead make your homepage template perform a $session->redirect($article->url); to the actual article page URL, and that way your homepage URL segment code would just be handling the requests that come in externally. Your local URLs would already be pointing to the /articles/article-url/. 

As for whether you are thinking too much, maybe. We're talking about micro optimization here. If you have a preference for using the /article-url/ URLs off the root, then that should carry more weight than the micro optimization. And if you are rendering pages off the root like that, make sure you are using <link rel='canonical'> tags in your document head so that the search engines don't think you've got duplicate content.

 

  • Like 2
Link to comment
Share on other sites

2 hours ago, deltavik said:

The article urls in my old site are in this format: http://domainname.com/article-url.

But, in PW, the urls look like this: http://domainname.com/articles/article-url. 

if you are worried of the urls because you are migrating the site and want to avoid 404s from old links, you can also use this awesome module:

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...