Too many sql queries issued creating a question from a bug report

Bug #245260 reported by Diogo Matsubara
4
Affects Status Importance Assigned to Milestone
Launchpad itself
Fix Released
Undecided
Guilherme Salgado

Bug Description

As seen in OOPS-915E1644 the +create-question page issues >2000 queries

So far it has not timeout badly, but the page needs optimization nevertheless

Revision history for this message
Curtis Hovey (sinzui) wrote :

The the code made too many queries for AnswerContacts and and the languages they speak. I have a branch the moves most the the logic into query.

Changed in malone:
assignee: nobody → sinzui-is
milestone: none → 2.1.11
status: New → In Progress
Revision history for this message
Curtis Hovey (sinzui) wrote :

Fix committed in RF 7222;

Changed in malone:
status: In Progress → Fix Committed
Revision history for this message
Curtis Hovey (sinzui) wrote :

I'm passing this to salgado because he has a comprehensive fix to deal with the underlying issue of person.preferredemail.

Changed in malone:
assignee: sinzui-is → salgado
status: Fix Committed → In Progress
Revision history for this message
Björn Tillenius (bjornt) wrote :

Salgado, what's the status of this fix?

Changed in malone:
milestone: 2.1.11 → 2.1.12
Revision history for this message
Guilherme Salgado (salgado) wrote : Re: [Bug 245260] Re: Too many sql queries issued creating a question from a bug report

My fix changes QuestionTargetMixin.answer_contacts to return decorated
IPerson objects (with their .languages pre-cached). I also did a few
hacks to make them compare equally to their non-decorated counterparts
and to make storm think they're Person objects.

The problem now is that these decorated objects get security-proxied
when .answer_contacts is called from outside of DB code, and there are
no security declarations for the class which decorates IPerson. Is
there a way to copy all the security declarations from a given class to
another one, in python, so that I don't have to duplicate all that zcml
we have to protect Person?

Revision history for this message
Francis J. Lacoste (flacoste) wrote :

Yes, there is:

withing the class definition you can use:

<class class="...">
   <require like_class="..." />
</class>

Revision history for this message
Guilherme Salgado (salgado) wrote :

The first approach I tried (with a decorated class caching all of a person's languages) didn't work because there's no way to make a decorated object's identity be the same as its non-decorated counterpart. That means we can't really mix them together, specially when we use them in a set().

My second approach makes Person.languages a cachedproperty, and changes .answer_contacts to pre-fill that cache for all answer contacts, thus issuing a single query.

Revision history for this message
Guilherme Salgado (salgado) wrote :

another tentative fix landed on r7381

Changed in malone:
status: In Progress → Fix Committed
Revision history for this message
Guilherme Salgado (salgado) wrote :

OOPS-1068S156 is from before the last fix landed. It reports a total of 3253 SQL statements, with nearly 2000 being SELECTs on the Language table.

These 2000 are all gone, as we can see on OOPS-1069S404.

However, that page still does around 400 INSERTs in the BugNotificationRecipient table and 200 SELECTs in the EmailAddress table, which account to almost half of its total statements (1354)

Revision history for this message
Guilherme Salgado (salgado) wrote :

Also note the non-sql-time reported in the OOPSes: more than 6 minutes!

Changed in malone:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.