← Back to team overview

launchpad-dev team mailing list archive

Re: reminder: test changed queries on qastaging *especially* for large tables *and* positively id as existing bugs any timeouts

 

Hi,

On Wed, Jun 22, 2011 at 9:42 PM, Francis J. Lacoste
<francis.lacoste@xxxxxxxxxxxxx> wrote:
> 2) When "tuning" queries, please leave in comments in the code! There
> was not comment here and thought naively that I should get rid of the
> extra query to get the archive ids and use a join instead. Bad bad idea
> it seemed. A comment explaining this non-intuitive query would have
> saved me re-learning that already learned lesson :-)

Even better is to write a test.  You can use Storm's tracing logic to
capture queries.  For example:

from cStringIO import StringIO
from storm.tracer import debug

def test_optimized_query(self):
    """
    A nice docstring explaining the special query you've written and why it
    needs to be written as such.
    """
    stream = StringIO()
    debug(True, stream)
    try:
        # Do a thing that runs your optimized query.
    finally:
        debug(False)
    self.assertIn("<optimized query>", stream.getvalue())

In the Landscape code base there's a helper method called
capture_statements (or something, I can't quite remember) that makes
this easier (you don't need the try/finally block).  There's also an
assertSQLIn method that makes comparing the actual query to what you
expect a bit easier (differences in whitespace can be annoying).
Anyway, it shouldn't be hard to cook up a nice way to do this kind of
thing.

Thanks,
J.


Follow ups

References