Merge lp:~deryck/launchpad/preload-tags-for-buglistings-901122 into lp:launchpad
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Deryck Hodge | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 14887 | ||||
Proposed branch: | lp:~deryck/launchpad/preload-tags-for-buglistings-901122 | ||||
Merge into: | lp:launchpad | ||||
Diff against target: |
201 lines (+58/-7) 7 files modified
lib/lp/bugs/browser/bugtask.py (+10/-2) lib/lp/bugs/browser/cvereport.py (+2/-1) lib/lp/bugs/browser/tests/test_bugtask.py (+4/-3) lib/lp/bugs/doc/bugtask.txt (+15/-0) lib/lp/bugs/interfaces/bugtask.py (+6/-0) lib/lp/bugs/model/bugtask.py (+18/-0) lib/lp/registry/browser/milestone.py (+3/-1) |
||||
To merge this branch: | bzr merge lp:~deryck/launchpad/preload-tags-for-buglistings-901122 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Robert Collins (community) | Approve | ||
Review via email: mp+95023@code.launchpad.net |
Commit message
[r=lifeless][bug=901122][incr] Load tags in a single query for custom buglistings.
Description of the change
This is the first branch of refactorings to load new data that was added in new buglistings without adding more queries. This first bit here is to get tags loaded as a set for a given buglisting batch, rather than accessing them in a loop for each item in the buglist.
I followed the pattern used for bug_badge_
There were a few test updates required, since the required arguments changed for BugTaskListingItem. I also updated doc/bugtask.txt to test the new BugTaskSet method. Otherwise, it's a pretty straight forward change.
This will certainly do the job. I have some things I would have done differently that you may wish to do, or not.
Firstly, using tags='' to indicate no-tags is horribly confusing when tags is a list the rest of the time. It works (because '' is iterable) but its confusing. I suggest using () instead.
Secondly, load_referencing or load_related would quite likely let you bring back all the tags with less code. to_task[ bugtag. bugID], bugtag.tag for bugtag in referencing( BugTag, tasks, ["bugID"]))
something like:
bug_to_task = dict((task.bugID, task.id) for task in tasks)
tags = dict((bug_
load_
Third, tags_for_batch is only used once and isn't directly tested. It seems a little ugly but I can see why you have it. I'd consider just passing the result down the call stack rather than caching it for the lifetime of the view.
I'd like to see a scaling test for this. Unless this is the entire remaining lazy load it won't be constant, but it will make the scaling clear and documented.