Ayende @ Rahien

Refunds available at head office

NH Prof New Feature: The Query Cache

Okay, I said it is not there yet, but I got annoyed by the lack of this feature, and I really had to make this work.

That one was a pretty tough one. It required me to make some minor modifications to NHiberante, as a result, this feature works with NHbierante r3976 or up only. What this means is that if you want to use this feature, you have to get it from the trunk.

This is the only feature in NH Prof that requires the trunk.

In this feature, we can see that we detect a cached query, and are able to display it properly.:

image

I am not sure how I should treat this for the purpose of analysis. Should this be grouped with the actual query? Should this be a separate entry?

Anyway, just for kicks, here is the test for the feature:

[TestFixture]
public class CachingTestFixture : IntegrationTestBase
{
    [Test]
    public void CanDetectCachedQueries()
    {
        ExecuteScenarioInDifferentAppDomain<UsingCacheQueries>();

    	var array = observer.Model.Sessions[2].Statements.OfType<StatementModel>()
    		.ToArray();
		Assert.AreEqual(@"Cached query: 
SELECT this_.Id             as Id7_0_,
   this_.Title          as Title7_0_,
   this_.Subtitle       as Subtitle7_0_,
   this_.AllowsComments as AllowsCo4_7_0_,
   this_.CreatedAt      as CreatedAt7_0_
FROM   Blogs this_
WHERE  this_.Title = 'The lazy blog' /* @p0 */
   and this_.Id = 1 /* @p1 */
", array[0].Text);
		Assert.AreEqual(@"Cached query: 
select blog0_.Id             as Id7_,
   blog0_.Title          as Title7_,
   blog0_.Subtitle       as Subtitle7_,
   blog0_.AllowsComments as AllowsCo4_7_,
   blog0_.CreatedAt      as CreatedAt7_
from   Blogs blog0_
where  ( blog0_.Title = 'The lazy blog' /* @p0 */ )
   and ( blog0_.Id = 1 /* @p1 */ )
", array[2].Text);
    }
}

As an aside, do you think that posting the tests is good? Should I just do the screen shots?

Comments

Davy Brion
01/06/2009 06:29 AM by
Davy Brion

very glad to see this feature as well as the last two that were introduced ;)

i'd leave the tests in these posts... it doesn't hurt anyone and it's interesting to at least some people

Krzysztof Kozmic
01/06/2009 06:44 AM by
Krzysztof Kozmic

I admire your work overall, and with Castle/NHibernate in particular. However I'm not sure I like the idea of changing NHibernate solely to make a 3rd party tool happy.

Tobin Harris
01/06/2009 08:23 AM by
Tobin Harris

Very nice feature :)

I know this is shrink wrapped software, but how about drawing a feature freeze for this iteration and getting R1 out the door? Then, give us an R2 in 2-4 weeks with more features :)

By the way, I LOVE the fact that you can modify NHibernate to make a feature possible. I see this as an advantage of Open Source software. I realise there's a potential for abuse there too, especially if the modifier benefits financially from the changes.

I also think your NHProf site is looking very concise, and cool. Have you considered linking to the site on each blog post, and also stating that the tool is available for download? (I realised this already, but I want to see a link regardless).

Krzysztof Kozmic
01/06/2009 08:57 AM by
Krzysztof Kozmic

Ayende,

It's not what I feared it would be. You're right, these changes benefit anyone using NHibernate, or at least thehy don't hurt anybody.

What I feared, was that you would start adding changes that would support NHProf, at the expense of making NHibernate less robust, harder to use, add no value for anyone else but NHProf, or hurting it overall in some other way.

Tuna Toksoz
01/06/2009 09:01 AM by
Tuna Toksoz

Krzysztof, isn't it the way oss work in general? If you need something, you implement something.

Krzysztof Kozmic
01/06/2009 09:03 AM by
Krzysztof Kozmic

Tuna,

Yes, but you fork it, if you are the only one that needs what you implement. Otherwise, you first make sure that the feature you implement is in sync with where the piece of software is going overall.

josh
01/06/2009 04:23 PM by
josh

thinking out loud.. if I'm looking at queries for my app, I want to know that it runs the first time properly, and uses cached query for subsequent calls...

Not regarding your UI, I'd envision it in a tree view or some way of drilling down.

Would it be possible to have a timeline view of the executed queries and a relational view (same queries together, possibly different params)?

Comments have been closed on this topic.