Jennifer S Posted February 23, 2013 Share Posted February 23, 2013 Hi. I'm using this as a selector to grab every page in my site that has a multi-page select field set to a particular value: $theseones = $pages->get( "/" )->find( "has_parent=/, tag_seasons=/tags/seasons/spring" ); Is this un-wise in terms of performance, etc? Cheers, Jenn Link to comment Share on other sites More sharing options...
apeisa Posted February 23, 2013 Share Posted February 23, 2013 You can drop the get("/") and use just pages find. Or alternatively keep the get, and use children instead of find and drop has_parent. Also you might consider using page object instead of path on tag_seasons, but that really depends about your site... If you are sure that season paths don't change then that is clean and nice. 1 Link to comment Share on other sites More sharing options...
Pete Posted February 23, 2013 Share Posted February 23, 2013 If tag_seasons is a page field as you say and "spring" is the name of a page in this case then you could do: $theseones = $pages->find("tag_seasons.name=spring"); I'm not sure whether it makes the search faster, but something I always do out of habit is specify the template as well (someone cleverer than me can clarify if it is beneficial, but I think it helps with readability of the code as you know at a glance what type of page you're expecting to get via the selector): $theseones = $pages->find("template=youretemplate, tag_seasons.name=spring"); 1 Link to comment Share on other sites More sharing options...
ryan Posted February 25, 2013 Share Posted February 25, 2013 Just want to mention that this: $theseones = $pages->get( "/" )->find( "has_parent=/, tag_seasons=/tags/seasons/spring" ); is identical to this: $theseones = $pages->find( "tag_seasons=/tags/seasons/spring" ); So there isn't any reason to have a $pages->get('/'); or a "has_parent=/" in your case. But lets say that you were targeting a branch in the structure like "/products/". In that, you would only need $pages->get('/products/')->find('tag_seasons=/tags/seasons/spring'); OR $pages->find("has_parent=/, tag_seasons=/tags/seasons/spring"); You wouldn't need both, as they are synonymous with each other. Link to comment Share on other sites More sharing options...
Pete Posted February 25, 2013 Share Posted February 25, 2013 Is there anything gained by specifyinh the template in the selector as well ryan or does that not save any time on the query? Link to comment Share on other sites More sharing options...
Jennifer S Posted February 26, 2013 Author Share Posted February 26, 2013 Ah, I see. It is easier to learn new things than to unlearn old things. This system is so elegant! 2 Link to comment Share on other sites More sharing options...
ryan Posted February 27, 2013 Share Posted February 27, 2013 Is there anything gained by specifyinh the template in the selector as well ryan or does that not save any time on the query? There are instances where it could feasibly reduce the potential data set that MySQL has to scan, but I think in most cases it probably doesn't make a difference to performance. But there are other good reasons to specify a template (or parent, or both). For one it clarifies what you are attempting to match, making it more "readable" to you and others that ever look at the code. It also ensures that the code is still matching the right things, should the field being searched for get added to more templates in the future. 1 Link to comment Share on other sites More sharing options...
Pete Posted February 27, 2013 Share Posted February 27, 2013 I think it was legibility of code and re-usability of fields that prompted me to get into that habit in the first place on a larger project, so it's nice to know it's a good habit I guess the only time you would be bothered about reducing the scan of the MySQL data set is with tens/hundreds of thousands of pages as so much is indexed in PW that it should be fast anyway? Link to comment Share on other sites More sharing options...
ryan Posted March 1, 2013 Share Posted March 1, 2013 I guess the only time you would be bothered about reducing the scan of the MySQL data set is with tens/hundreds of thousands of pages as so much is indexed in PW that it should be fast anyway? Theoretically, the more specific you can be with a query, the more potential there is for it to use the best index and locate things faster. But if there aren't other templates using the field you are finding anyway, then it's also possible it could add overhead (though probably not measurable). But like I said, I think more specificity is better overall. Anything you can specify from a selector in terms of finding pages should ultimately be using an index in the DB, except for keywords in %= queries. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now