Soyuz code uses .count() too much when all it needs is a bool

Bug #701947 reported by Julian Edwards
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Launchpad itself
Fix Released
High
Julian Edwards

Bug Description

Since SQLObject has a fixed __nonzero__ on the ResultSet, we can use bool() instead of counting (which is very inefficient).

We can also replace code like this:

- if pub_hist.count() == 0:
+ try:
+ return pub_hist[0]
+ except IndexError:
             return None
- return pub_hist[0]

and avoid the issue entirely.

Related branches

Changed in launchpad:
status: New → In Progress
importance: Undecided → High
assignee: nobody → Julian Edwards (julian-edwards)
tags: added: tech-debt
Revision history for this message
Jonathan Lange (jml) wrote :

ResultSet also has efficient is_empty() and one() methods. one() achieves pretty much exactly that snippet.

Revision history for this message
Julian Edwards (julian-edwards) wrote : Re: [Bug 701947] Re: Soyuz code uses .count() too much when all it needs is a bool

On Wednesday 12 January 2011 15:55:39 Jonathan Lange wrote:
> ResultSet also has efficient is_empty() and one() methods. one()
> achieves pretty much exactly that snippet.

Unfortunately SQLObjectResultSet does not have those, hence the change.

Revision history for this message
Launchpad QA Bot (lpqabot) wrote : Bug fixed by a commit

Fixed in stable r12203 (http://bazaar.launchpad.net/~launchpad-pqm/launchpad/stable/revision/12203) by a commit, but not testable.

Changed in launchpad:
milestone: none → 11.02
tags: added: qa-untestable
Changed in launchpad:
status: In Progress → Fix Committed
Curtis Hovey (sinzui)
Changed in launchpad:
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.