1fab075a58052c812dc69b9609cc987b400985cc
hiram
  Mon Apr 22 22:05:40 2019 -0700
getting to api functions immediately no cart involved refs #18869

diff --git src/hg/hubApi/getData.c src/hg/hubApi/getData.c
index ad7adab..94e545b 100644
--- src/hg/hubApi/getData.c
+++ src/hg/hubApi/getData.c
@@ -364,33 +364,33 @@
     char *words[8];
     int wordCount;
     wordCount = chopLine(cloneString(tdb->type), words);
     if ( (wordCount > 1) && startsWith("bigBed", words[0]))
 	{
 	if (isAllDigits(words[1]))
 	   if (8 < sqlUnsigned(words[1]))
 		return TRUE;
 	}
     else
 	return TRUE;	/* something other than bigBed */
     }
 return FALSE;
 }
 
-static void bbiDataOutput(struct jsonWrite *jw, struct bbiFile *bbi,
+static unsigned bbiDataOutput(struct jsonWrite *jw, struct bbiFile *bbi,
     char *chrom, unsigned start, unsigned end, struct sqlFieldType *fiList,
-     struct trackDb *tdb)
+     struct trackDb *tdb, unsigned itemsDone)
 /* output bed data for one chrom in the given bbi file */
 {
 char *itemRgb = trackDbSetting(tdb, "itemRgb");
 if (typedBig9Plus(tdb))
     itemRgb = "on";
 int *jsonTypes = NULL;
 int columnCount = slCount(fiList);
 AllocArray(jsonTypes, columnCount);
 int i = 0;
 struct sqlFieldType *fi;
 for ( fi = fiList; fi; fi = fi->next)
     {
     if (itemRgb)
 	{
 	if (8 == i && sameWord("on", itemRgb))
@@ -417,30 +417,31 @@
 	jsonWriteListStart(jw, NULL);
 	for (i = 0; i < bbi->fieldCount; ++i)
 	    jsonDatumOut(jw, NULL, row[i], jsonTypes[i]);
 	jsonWriteListEnd(jw);
         }
     else
         {
 	jsonWriteObjectStart(jw, NULL);
 	for (i = 0; i < bbi->fieldCount; ++i, fi = fi->next)
 	    jsonDatumOut(jw, fi->name, row[i], jsonTypes[i]);
 	jsonWriteObjectEnd(jw);
         }
     ++itemCount;
     }
 lmCleanup(&bbLm);
+return itemCount;
 }	/* static void bbiDataOutput(struct jsonWrite *jw, . . . ) */
 
 static void wigDataOutput(struct jsonWrite *jw, struct bbiFile *bwf,
     char *chrom, unsigned start, unsigned end)
 /* output wig data for one chrom in the given bwf file */
 {
 struct lm *lm = lmInit(0);
 struct bbiInterval *iv, *ivList = bigWigIntervalQuery(bwf, chrom, start, end, lm);
 if (NULL == ivList)
     return;
 
 unsigned itemCount = 0;
 
 jsonWriteListStart(jw, chrom);
 for (iv = ivList; iv && itemCount < maxItemsOutput; iv = iv->next)
@@ -581,40 +582,43 @@
     jsonWriteNumber(jw, "start", uStart);
     jsonWriteNumber(jw, "end", uEnd);
     }
 
 jsonWriteString(jw, "bigDataUrl", bigDataUrl);
 jsonWriteString(jw, "trackType", thisTrack->type);
 
 if (allowedBigBedType(thisTrack->type))
     {
     struct asObject *as = bigBedAsOrDefault(bbi);
     struct sqlFieldType *fiList = sqlFieldTypesFromAs(as);
     if (jsonOutputArrays || debug)
         bigColumnTypes(jw, fiList, as);
 
     jsonWriteListStart(jw, track);
+    unsigned itemsDone = 0;
     if (isEmpty(chrom))
 	{
 	struct bbiChromInfo *bci;
-	for (bci = chromList; bci; bci = bci->next)
+	for (bci = chromList; (itemsDone < maxItemsOutput) && bci; bci = bci->next)
 	    {
-	    bbiDataOutput(jw, bbi, bci->name, 0, bci->size, fiList, thisTrack);
+	    itemsDone += bbiDataOutput(jw, bbi, bci->name, 0, bci->size,
+		fiList, thisTrack, itemsDone);
 	    }
 	}
     else
-	bbiDataOutput(jw, bbi, chrom, uStart, uEnd, fiList, thisTrack);
+	itemsDone += bbiDataOutput(jw, bbi, chrom, uStart, uEnd, fiList,
+		thisTrack, itemsDone);
     jsonWriteListEnd(jw);
     }
 else if (startsWith("bigWig", thisTrack->type))
     {
     if (jsonOutputArrays || debug)
 	wigColumnTypes(jw);
     jsonWriteObjectStart(jw, track);
     wigData(jw, bbi, chrom, uStart, uEnd);
     jsonWriteObjectEnd(jw);
     }
 bbiFileClose(&bbi);
 apiFinishOutput(0, NULL, jw);
 }	/*	static void getHubTrackData(char *hubUrl)	*/
 
 static void getTrackData()
@@ -761,40 +765,43 @@
 /* when start, end given, show them */
 if ( uEnd > uStart )
     {
     jsonWriteNumber(jw, "start", uStart);
     jsonWriteNumber(jw, "end", uEnd);
     }
 
 if (allowedBigBedType(thisTrack->type))
     {
     struct asObject *as = bigBedAsOrDefault(bbi);
     struct sqlFieldType *fiList = sqlFieldTypesFromAs(as);
     if (jsonOutputArrays || debug)
         bigColumnTypes(jw, fiList, as);
 
     jsonWriteListStart(jw, track);
+    unsigned itemsDone = 0;
     if (isEmpty(chrom))
 	{
 	struct bbiChromInfo *bci;
-	for (bci = chromList; bci; bci = bci->next)
+	for (bci = chromList; (itemsDone < maxItemsOutput) && bci; bci = bci->next)
 	    {
-	    bbiDataOutput(jw, bbi, bci->name, 0, bci->size, fiList, thisTrack);
+	    itemsDone += bbiDataOutput(jw, bbi, bci->name, 0, bci->size,
+		fiList, thisTrack, itemsDone);
 	    }
 	}
     else
-	bbiDataOutput(jw, bbi, chrom, uStart, uEnd, fiList, thisTrack);
+	itemsDone += bbiDataOutput(jw, bbi, chrom, uStart, uEnd, fiList,
+		thisTrack, itemsDone);
     jsonWriteListEnd(jw);
     }
 else if (startsWith("bigWig", thisTrack->type))
     {
     if (jsonOutputArrays || debug)
 	wigColumnTypes(jw);
 
     jsonWriteObjectStart(jw, track);
     wigData(jw, bbi, chrom, uStart, uEnd);
     jsonWriteObjectEnd(jw);
     bbiFileClose(&bbi);
     }
 else
     tableDataOutput(db, thisTrack, conn, jw, track, chrom, uStart, uEnd);