]> git.donarmstrong.com Git - dak.git/commitdiff
Contents: use the new string_agg() function of Pg9.
authorTorsten Werner <twerner@debian.org>
Tue, 22 Mar 2011 13:18:55 +0000 (13:18 +0000)
committerTorsten Werner <twerner@debian.org>
Tue, 22 Mar 2011 13:18:55 +0000 (13:18 +0000)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/contents.py
tests/dbtest_contents.py
tests/fixtures/dak.conf

index 27ffdda6cf71879c75abd34b01ee98d3b2fe796c..5bf94d9a252da7c7bdd5a6c10d70b408294b5dab 100755 (executable)
@@ -92,10 +92,10 @@ unique_override as
         where o.suite = :overridesuite and o.type = :type_id and o.section = s.id and
         o.component = :component)
 
-select bc.file, o.section || '/' || b.package as package
+select bc.file, string_agg(o.section || '/' || b.package, ',' order by b.package) as pkglist
     from newest_binaries b, bin_contents bc, unique_override o
     where b.id = bc.binary_id and o.package = b.package
-    order by bc.file, b.package'''
+    group by bc.file'''
 
         else:
             sql = '''
@@ -120,36 +120,26 @@ unique_override as
         where o.suite = :overridesuite and o.type = :type_id and o.section = s.id
         order by o.package, s.section, o.modified desc)
 
-select bc.file, o.section || '/' || b.package as package
+select bc.file, string_agg(o.section || '/' || b.package, ',' order by b.package) as pkglist
     from newest_binaries b, bin_contents bc, unique_override o
     where b.id = bc.binary_id and o.package = b.package
-    order by bc.file, b.package'''
+    group by bc.file'''
 
-        return self.session.query("file", "package").from_statement(sql). \
+        return self.session.query("file", "pkglist").from_statement(sql). \
             params(params)
 
     def formatline(self, filename, package_list):
         '''
         Returns a formatted string for the filename argument.
         '''
-        package_list = ','.join(package_list)
         return "%-55s %s\n" % (filename, package_list)
 
     def fetch(self):
         '''
         Yields a new line of the Contents-$arch.gz file in filename order.
         '''
-        last_filename = None
-        package_list = []
-        for filename, package in self.query().yield_per(100):
-            if filename != last_filename:
-                if last_filename is not None:
-                    yield self.formatline(last_filename, package_list)
-                last_filename = filename
-                package_list = []
-            package_list.append(package)
-        if last_filename is not None:
-            yield self.formatline(last_filename, package_list)
+        for filename, package_list in self.query().yield_per(100):
+            yield self.formatline(filename, package_list)
         # end transaction to return connection to pool
         self.session.rollback()
 
index 43cf838cace46628e59c32872dfca1b36834b533..622e4aaf80d857fa16247c2e779253a794ec01a7 100755 (executable)
@@ -145,9 +145,7 @@ class ContentsTestCase(DBDakTestCase):
             cw.get_list())
         # test formatline and sort order
         self.assertEqual('/usr/bin/hello                                          python/hello\n', \
-            cw.formatline('/usr/bin/hello', ['python/hello']))
-        self.assertEqual('/usr/bin/hello                                          editors/emacs,python/hello,utils/sl\n', \
-            cw.formatline('/usr/bin/hello', ['editors/emacs', 'python/hello', 'utils/sl']))
+            cw.formatline('/usr/bin/hello', 'python/hello'))
         # test output_filename
         self.assertEqual('tests/fixtures/ftp/dists/squeeze/Contents-i386.gz', \
             normpath(cw.output_filename()))
index abfa251171cc52c367aaded3ddb70c5367220d7a..6f68238da95f913c3b23e4c6f9c95f65ef118bc6 100644 (file)
@@ -29,5 +29,6 @@ DB
   Name "test_projectb";
   Host "";
   Port -1;
+  Unicode false;
 };