a2cbff13a70c454dfb455027e96bd5afe7a01170
chmalee
  Tue Mar 16 16:42:27 2021 -0700
Fix up relatedTracks section on hgTrackUi/hgc pages to not choke on superTracks, and don't show duplicate tracks, refs #25721

diff --git src/hg/lib/hui.c src/hg/lib/hui.c
index 4f30426..65c6c26 100644
--- src/hg/lib/hui.c
+++ src/hg/lib/hui.c
@@ -9868,41 +9868,53 @@
     return;
     }
 
 char query[256];
 sqlSafef(query, sizeof(query),
     "select track1, track2, why from %s where track1='%s' or track2='%s'", relatedTrackTable, tdb->track, tdb->track);
 
 char **row;
 struct sqlResult *sr;
 sr = sqlGetResult(conn, query);
 row = sqlNextRow(sr);
 if (row != NULL)
     {
     puts("<b>Related tracks</b>\n");
     puts("<ul>\n");
+    struct hash *otherTracksAndDesc = hashNew(0);
     char *track1, *track2, *why, *otherTrack;
     for (; row != NULL; row = sqlNextRow(sr))
         {
         track1 = row[0];
         track2 = row[1];
         why    = row[2];
 
         if (sameWord(track1, tdb->track))
             otherTrack = track2;
         else
             otherTrack = track1;
+        // hopefully relatedTracks.ra doesn't have dupes but hash them just in case
+        hashReplace(otherTracksAndDesc, cloneString(otherTrack), cloneString(why));
+        }
 
+    struct hashEl *hel, *helList = hashElListHash(otherTracksAndDesc);
+    for (hel = helList; hel != NULL; hel = hel->next)
+        {
+        char *otherTrack = (char *)hel->name;
+        char *why = (char *)hel->val;
         struct trackDb *otherTdb = hashFindVal(trackHash, otherTrack);
+        // super tracks are not in the hash:
+        if (!otherTdb)
+            otherTdb = tdbForTrack(database, otherTrack, NULL);
         if (otherTdb)
             {
             puts("<li>");
             printf("<a href=\"%s?g=%s&%s\">%s</a>", hTrackUiForTrack(otherTdb->track), otherTdb->track, cartSidUrlString(cart), otherTdb->shortLabel);
             puts(": ");
             puts(why);
             }
         }
         puts("</ul>\n");
     }
 sqlFreeResult(&sr);
 hFreeConn(&conn);
 }