cd40e92bef563b1581ea25e4842c884bf5b32efd
braney
  Mon Jan 15 13:18:03 2024 -0800
limit maxItems to maxItemsPerRow (1,000).   Use one million for the
number of items to request from a bigBed file

diff --git src/hg/hgTracks/bigBedTrack.c src/hg/hgTracks/bigBedTrack.c
index c00e0e9..ca3b011 100644
--- src/hg/hgTracks/bigBedTrack.c
+++ src/hg/hgTracks/bigBedTrack.c
@@ -17,30 +17,31 @@
 #include "wigCommon.h"
 #include "bbiFile.h"
 #include "obscure.h"
 #include "bigWig.h"
 #include "bigBed.h"
 #include "bigWarn.h"
 #include "errCatch.h"
 #include "trackHub.h"
 #include "net.h"
 #include "bigPsl.h"
 #include "bigBedFilter.h"
 #include "bigBedLabel.h"
 #include "variation.h"
 #include "chromAlias.h"
 #include "instaPort.h"
+#include "hgConfig.h"
 
 static unsigned getFieldNum(struct bbiFile *bbi, char *field)
 // get field number for field name in bigBed.  errAbort if field not found.
 {
 int fieldNum =  bbFieldIndex(bbi, field);
 if (fieldNum < 0)
     fieldNum = defaultFieldLocation(field);
 if (fieldNum < 0)
     errAbort("error building filter with field %s.  Field not found.", field);
 
 return fieldNum;
 }
 
 struct bigBedFilter *bigBedMakeNumberFilter(struct cart *cart, struct bbiFile *bbi, struct trackDb *tdb, char *filter, char *defaultLimits,  char *field)
 /* Make a filter on this column if the trackDb or cart wants us to. */
@@ -380,62 +381,82 @@
 	if (!trackHubDatabase(database))
 	    conn = hAllocConnTrack(database, track->tdb);
 	fileName = bbiNameFromSettingOrTable(track->tdb, conn, track->table);
 	hFreeConn(&conn);
 	}
     
     #ifdef USE_GBIB_PWD
     #include "gbib.c"
     #endif
 
     bbi = track->bbiFile = bigBedFileOpenAlias(fileName, chromAliasFindAliases);
     }
 return bbi;
 }
 
+static unsigned bigBedMaxItems()
+/* Get the maximum number of items to grab from a bigBed file.  Defaults to a million. */
+{
+static boolean set = FALSE;
+static unsigned maxItems = 0;
+
+if (!set)
+    {
+    char *maxItemsStr = cfgOptionDefault("bigBedMaxItems", "1000000");
+
+    maxItems = sqlUnsigned(maxItemsStr);
+    }
+
+return maxItems;
+}
+
 struct bigBedInterval *bigBedSelectRangeExt(struct track *track,
 	char *chrom, int start, int end, struct lm *lm, int maxItems)
 /* Return list of intervals in range. */
 {
 struct bigBedInterval *result = NULL;
 /* protect against temporary network error */
 struct errCatch *errCatch = errCatchNew();
 if (errCatchStart(errCatch))
     {
     struct bbiFile *bbi = fetchBbiForTrack(track);
-    result = bigBedIntervalQuery(bbi, chrom, start, end, maxItems + 1, lm);
-    if (slCount(result) > maxItems)
+    result = bigBedIntervalQuery(bbi, chrom, start, end, bigBedMaxItems() + 1, lm);
+    if (slCount(result) > bigBedMaxItems())
 	{
+        errAbort("Too many items in window to filter.Zoom in or remove filters to view track.");
+
+#ifdef NOTNOW  // we may want to use summary levels if filters are off and folks don't want color
 	track->limitedVis = tvDense;
 	track->limitedVisSet = TRUE;
 	result = NULL;
 	AllocArray(track->summary, insideWidth);
 	if (bigBedSummaryArrayExtended(bbi, chrom, start, end, insideWidth, track->summary))
 	    {
 	    char *denseCoverage = trackDbSettingClosestToHome(track->tdb, "denseCoverage");
 	    if (denseCoverage != NULL)
 		{
 		double endVal = atof(denseCoverage);
 		if (endVal <= 0)
 		    {
 		    AllocVar(track->sumAll);
 		    *track->sumAll = bbiTotalSummary(bbi);
 		    }
 		}
 	    }
 	else
 	    freez(&track->summary);
+#endif
 	}
     track->bbiFile = NULL;
     }
 errCatchEnd(errCatch);
 if (errCatch->gotError)
     {
     track->networkErrMsg = cloneString(errCatch->message->string);
     track->drawItems = bigDrawWarning;
     track->totalHeight = bigWarnTotalHeight;
     result = NULL;
     }
 errCatchFree(&errCatch);
 
 return result;
 }