[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master 1/4] Contents: use the new string_agg() function of Pg9.



Signed-off-by: Torsten Werner <twerner@debian.org>
---
 daklib/contents.py       |   24 +++++++-----------------
 tests/dbtest_contents.py |    4 +---
 tests/fixtures/dak.conf  |    1 +
 3 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/daklib/contents.py b/daklib/contents.py
index 27ffdda..5bf94d9 100755
--- a/daklib/contents.py
+++ b/daklib/contents.py
@@ -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()
 
diff --git a/tests/dbtest_contents.py b/tests/dbtest_contents.py
index 43cf838..622e4aa 100755
--- a/tests/dbtest_contents.py
+++ b/tests/dbtest_contents.py
@@ -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()))
diff --git a/tests/fixtures/dak.conf b/tests/fixtures/dak.conf
index abfa251..6f68238 100644
--- a/tests/fixtures/dak.conf
+++ b/tests/fixtures/dak.conf
@@ -29,5 +29,6 @@ DB
   Name "test_projectb";
   Host "";
   Port -1;
+  Unicode false;
 };
 
-- 
1.7.2.5



Reply to: