X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fstats.py;h=7c61e2a42948fa58e2bce7a0d50493d981ebfee0;hb=cac810b4aeb8fa34c8ccaa7dc35b081efddc606b;hp=6856fa105f19a2591f993a1e03bc6978cc971f2f;hpb=0dada7c5846e0ae676bbe0b81c1065fe75ca9b86;p=dak.git diff --git a/dak/stats.py b/dak/stats.py index 6856fa10..7c61e2a4 100755 --- a/dak/stats.py +++ b/dak/stats.py @@ -34,8 +34,7 @@ import sys import apt_pkg from daklib import utils -from daklib.dbconn import DBConn, get_suite_architectures, Suite, Architecture, \ - BinAssociation +from daklib.dbconn import DBConn, get_suite_architectures, Suite, Architecture ################################################################################ @@ -129,12 +128,6 @@ def output_format(suite): output_suite.append(word[0]) return "-".join(output_suite) -# Obvious query with GROUP BY and mapped names -> 50 seconds -# GROUP BY but ids instead of suite/architecture names -> 28 seconds -# Simple query -> 14 seconds -# Simple query into large dictionary + processing -> 21 seconds -# Simple query into large pre-created dictionary + processing -> 18 seconds - def number_of_packages(): arches = {} arch_ids = {} @@ -158,13 +151,14 @@ def number_of_packages(): # Get the raw data for binaries # Simultate 'GROUP by suite, architecture' with a dictionary # XXX: Why don't we just get the DB to do this? - for i in session.query(BinAssociation): - suite_id = i.suite_id - arch_id = i.binary.arch_id - d[suite_id][arch_id] = d[suite_id][arch_id] + 1 + for i in session.execute("""SELECT suite, architecture, COUNT(suite) + FROM bin_associations + LEFT JOIN binaries ON bin = binaries.id + GROUP BY suite, architecture""").fetchall(): + d[ i[0] ][ i[1] ] = i[2] # Get the raw data for source arch_id = arch_ids["source"] - for i in session.execute('SELECT suite, COUNT(suite) FROM src_associations GROUP BY suite').all(): + for i in session.execute('SELECT suite, COUNT(suite) FROM src_associations GROUP BY suite').fetchall(): (suite_id, count) = i d[suite_id][arch_id] = d[suite_id][arch_id] + count ## Print the results @@ -198,7 +192,7 @@ def number_of_packages(): output = output + arch.center(longest_arch)+" |" for suite_id in suite_id_list: if suite_arches[suite_id].has_key(arch): - count = repr(d[suite_id][arch_id]) + count = "%d" % d[suite_id][arch_id] else: count = "-" output = output + count.rjust(longest_suite)+" |"