c4e21e1e64356236569f1c709cbb01f84875daa8
tdreszer
  Fri Dec 10 08:56:10 2010 -0800
Added tdbForTrack to replace hTrackDbForTrack.  New version allows passing in the list of tdbs, so that the list is not regenerated time and time again.
diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index 447743d..6c0bac9 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -3373,30 +3373,36 @@
 hashFree(&loaded);
 
 /* fill in supertrack fields, if any in settings */
 trackDbSuperMarkup(tdbList);
 trackDbAddTableField(tdbList);
 return tdbList;
 }
 
 static void addTrackIfDataAccessible(char *database, struct trackDb *tdb,
 	       boolean privateHost, struct trackDb **tdbRetList)
 /* check if a trackDb entry should be included in display, and if so
  * add it to the list, otherwise free it */
 {
 if ((!tdb->private || privateHost) && hTableForTrack(database, tdb->table) != NULL)
     slAddHead(tdbRetList, tdb);
+else if (sameWord(tdb->type,"downloadsOnly"))
+    {
+    if (sameString(tdb->table,tdb->track))
+        tdb->table = NULL;
+    slAddHead(tdbRetList, tdb);
+    }
 else
     trackDbFree(&tdb);
 }
 
 #ifdef UNUSED
 static void inheritFieldsFromParents(struct trackDb *tdb, struct trackDb *parent)
 /* Inherit undefined fields (outside of settings) from parent. */
 {
 if (tdb->shortLabel == NULL)
     tdb->shortLabel = cloneString(parent->shortLabel);
 if (tdb->type == NULL)
     tdb->type = cloneString(parent->type);
 if (tdb->longLabel == NULL)
     tdb->longLabel = cloneString(parent->longLabel);
 if (tdb->restrictList == NULL)
@@ -3612,40 +3618,49 @@
 struct sqlConnection *conn = hAllocConn(db);
 char where[256];
 safef(where, sizeof(where),
    "settings rlike '^(.*\n)?superTrack %s([ \n].*)?$' order by priority desc",
     tdb->track);
 tdb->subtracks = loadAndLookupTrackDb(conn, where);       // TODO: Straighten out when super points to children and when not!
 struct trackDb *subTdb;
 for (subTdb = tdb->subtracks; subTdb != NULL; subTdb = subTdb->next)
     {
     subTdb->parent = tdb;
     trackDbSuperMemberSettings(subTdb);
     }
 hFreeConn(&conn);
 }
 
-struct trackDb *hTrackDbForTrack(char *db, char *track)
+struct trackDb *tdbForTrack(char *db, char *track,struct trackDb **tdbList)
 /* Load trackDb object for a track. If track is composite, its subtracks
  * will also be loaded and inheritance will be handled; if track is a
  * subtrack then inheritance will be handled.  (Unless a subtrack has
  * "noInherit on"...) This will die if the current database does not have
- * a trackDb, but will return NULL if track is not found. */
+ * a trackDb, but will return NULL if track is not found.
+ * MAY pass in prepopulated trackDb list, or may receive the trackDb list as an inout. */
 {
 /* Get track list .*/
-struct trackDb *tdbList = hTrackDb(db);
-return rFindTrack(0, tdbList, track);
+struct trackDb *theTdbs = NULL;
+if (tdbList == NULL || *tdbList == NULL)
+    {
+    theTdbs = hTrackDb(db);
+    if (tdbList != NULL)
+        *tdbList = theTdbs;
+    }
+else
+    theTdbs = *tdbList;
+return rFindTrack(0, theTdbs, track);
 }
 
 struct trackDb *hTrackDbForTrackAndAncestors(char *db, char *track)
 /* Load trackDb object for a track. If need be grab its ancestors too.
  * This does not load children. hTrackDbForTrack will handle children, and
  * is actually faster if being called on lots of tracks.  This function
  * though is faster on one or two tracks. */
 {
 uglyf("hTrackDbForTrackAndAncestors(%s,%s)\n", db, track);
 struct sqlConnection *conn = hAllocConn(db);
 struct trackDb *tdb = loadTrackDbForTrack(conn, track);
 struct trackDb *ancestor = tdb;
 for (;;)
     {
     /* Get name of previous generation if any handling both