Soyuz code uses .count() too much when all it needs is a bool
Bug #701947 reported by
Julian Edwards
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
lp:~julian-edwards/launchpad/count-cull
- Robert Collins (community): Approve
-
Diff: 379 lines (+60/-66)13 files modifiedlib/lp/soyuz/adapters/archivedependencies.py (+3/-5)
lib/lp/soyuz/browser/archive.py (+8/-14)
lib/lp/soyuz/browser/build.py (+1/-1)
lib/lp/soyuz/model/archive.py (+1/-1)
lib/lp/soyuz/model/archivepermission.py (+16/-13)
lib/lp/soyuz/model/binarypackagebuild.py (+2/-2)
lib/lp/soyuz/model/distroseriessourcepackagerelease.py (+3/-2)
lib/lp/soyuz/model/publishing.py (+4/-4)
lib/lp/soyuz/model/queue.py (+9/-8)
lib/lp/soyuz/scripts/initialise_distroseries.py (+9/-9)
lib/lp/soyuz/scripts/packagecopier.py (+2/-2)
lib/lp/soyuz/scripts/ppa_add_missing_builds.py (+1/-1)
lib/lp/soyuz/scripts/publishdistro.py (+1/-4)
Changed in launchpad: | |
status: | New → In Progress |
importance: | Undecided → High |
assignee: | nobody → Julian Edwards (julian-edwards) |
tags: | added: tech-debt |
Changed in launchpad: | |
status: | Fix Committed → Fix Released |
To post a comment you must log in.
ResultSet also has efficient is_empty() and one() methods. one() achieves pretty much exactly that snippet.