← Back to team overview

launchpad-dev team mailing list archive

Filtering out conjoined/private bugs in python with no extra DB queries

 

Hi there,

In order to implement https://dev.launchpad.net/Projects/WorkItems we
have a  query for BugTasks that returns all tasks assigned to any member
of a team and whose milestone has a due date before a certain cutoff
date.  AFAICT, I cannot use BugTaskSet.search() for that because there
we cannot search for tasks assigned to any members of a team or across
all tasks with milestones (we can only filter by a single milestone or
not filter by milestone at all).  Adding support for those two things
there seemed quite complex to me, so I wrote my own query which does
just what we want.  It fetches all the bugtasks we need, together with
the associated objects that will be used to render that page, all in a
single query.

However, after that I realized we need to filter out the private bugs
the user is not allowed to see, as well as the slave tasks of conjoined
relationships.  At that point things started to get a bit complicated
because I'd end up duplicating some complex bits of SQL to filter out
those things, and that's not something I want to do.

Given that there will be no batching on that new page, I thought that
maybe I could filter out the conjoined slaves in python, but it turns
out BugTask.conjoined_master issues a bunch of queries (5 in some cases,
apparently because it calls bug.bugtasks which preloads
assignee,owner,bugwatch as well), so that doesn't seem to be a viable
alternative.  In my case, though, I only want to figure out whether or
not I can skip that task (I don't need a reference to the conjoined
task), and I might even skip the master and leave the slave, as the
important thing for the user of that page is the state/milestone the
task is in, so I think I could get away with something like this, which
should return True for the master task of a conjoined relationship:

  (This is for ProductSeries tasks; need similar for DistroSeries)
  if productseries is not None and product is None:
      if (productseries.id == productseries.product.development_focusID
          and task.status not in BugTask._NON_CONJOINED_STATUSES):
          continue

The above would skip the master tasks in a conjoined relationship,
leaving the slave in the list returned to the page, but it would not
cause extra queries since I fetch the product/productseries as well. I'd
like to know if that's reasonable or if there's a better way (which
doesn't involve rewriting bug searching in LP ;) to achieve what I want?

Oh, and I have the same kind of problem to filter out private bugs, but
I'm hoping there the extra queries issued when filtering them out in
python are not too big a deal because there shouldn't be many private
bugs in that page (for the vast majority of teams, at least) and the
checks to decide whether or not to show a private bug should consist
mostly of inTeam() calls, which are cached.  I'm going to write some
tests to check how many extra queries that would incur (assuming I fetch
the bug's owner as well), but I'd like to know if you guys think it's
possible we can afford that sort of thing?

-- 
Guilherme Salgado <https://launchpad.net/~salgado>

Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups