Each navigate requires two redundant queries
While debugging the (surprisingly) long query logs in YellowGrass, I found the cause of many of these queries: Each navigate triggers two queries. More interestingly, both are redundant. For example, take the following template:
define template tags(i : Issue) { for(tag : Tag in i.tags) { navigate(tag(i.project, tag.name)){output(tag.name)} } }
Hibernate will do a query with a join to load the issue together with its tags in one go (nicely efficient). Next, while looping over the tags, it will load the meta-tags of each of the tags in one join-query (also nicely efficient). If we would just do an output, that’s it for querying. However, if we do a navigate like above, we get two additional and equivalent queries for each tag. Both of which are redundant, since the information is already loaded by the earlier queries. For example, for an issue tagged with @sandervermolen and feature, we get:
Submitted by Sander Vermolen on 20 April 2011 at 10:48select tag0_.id as id10_, tag0_.`_description` as column3_10_, tag0_.`_name` as column4_10_, tag0_.Tag_project as Tag6_10_, tag0_.version_opt_lock as version5_10_ from _Tag tag0_ where tag0_.`_name`='feature' and tag0_.Tag_project='19ea74981cd8481692f06ca877f00f69' limit ? select tag0_.id as id10_, tag0_.`_description` as column3_10_, tag0_.`_name` as column4_10_, tag0_.Tag_project as Tag6_10_, tag0_.version_opt_lock as version5_10_ from _Tag tag0_ where tag0_.`_name`='feature' and tag0_.Tag_project='19ea74981cd8481692f06ca877f00f69' limit ? select tag0_.id as id10_, tag0_.`_description` as column3_10_, tag0_.`_name` as column4_10_, tag0_.Tag_project as Tag6_10_, tag0_.version_opt_lock as version5_10_ from _Tag tag0_ where tag0_.`_name`='@sandervermolen' and tag0_.Tag_project='19ea74981cd8481692f06ca877f00f69' limit ? select tag0_.id as id10_, tag0_.`_description` as column3_10_, tag0_.`_name` as column4_10_, tag0_.Tag_project as Tag6_10_, tag0_.version_opt_lock as version5_10_ from _Tag tag0_ where tag0_.`_name`='@sandervermolen' and tag0_.Tag_project='19ea74981cd8481692f06ca877f00f69' limit ?
Issue Log
Ok, I now also found what triggers the queries: it is the access control on tag(…). The page gets a project and a feature name as parameters. The check is unaware that such an issue is already loaded, which from a java perspective makes sense. Not sure why it is ran twice btw.
The problem would then be solved by using the tag as parameter to the tag page. But this gives ugly urls. Using name twice (like is done in databases) would be a solution, but that is not supported I suppose. Maybe naming a derived property(?)
Log in to post comments