Alex Willmer avatar Alex Willmer committed 266812b Merge

Merge from ticket-links-trunk

Comments (0)

Files changed (1)

trac/ticket/model.py

 # Author: Jonas Borgström <jonas@edgewall.com>
 #         Christopher Lenz <cmlenz@gmx.de>
 
+import itertools
+import operator
 import re
 from datetime import date, datetime
 
                 
         # Fetch links 
         link_fields = [f['name'] for f in self.fields if f.get('link')]
+        cursor.execute("""SELECT type, destination 
+                       FROM ticket_links
+                       WHERE source=%%s and type IN (%s)
+                       ORDER BY type, destination
+                       """ 
+                       % ','.join(['%s'] * len(link_fields)), 
+                       [tkt_id] + link_fields)
+        grouped_recs = itertools.groupby(cursor, operator.itemgetter(0))
+        link_values = dict((end, ', '.join(['#%s' % r[1] for r in recs]))
+                           for end, recs in grouped_recs)
         for end in link_fields:
-            cursor.execute("""
-                SELECT destination FROM ticket_links
-                WHERE source=%s and type=%s
-            """, (tkt_id, end))
-            link_list = []
-            for destination in cursor:
-                link_list.append(destination)
-
-            link_list.sort()
-            self.values[end] = ', '.join(['#%s' % v for v in link_list])
+            self.values[end] = link_values.get(end, '')
             
 
     def __getitem__(self, name):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.