df0b444ffb7c4b4f6ec8e745ad0e0f22b46cd15f
galt
  Thu Apr 24 02:29:22 2025 -0700
Found hgNear as a highly executed CGI on RR, added botDelay. No rm.

diff --git src/hg/near/hgNear/hgNear.c src/hg/near/hgNear/hgNear.c
index 00206d903fb..cde2ff7cd25 100644
--- src/hg/near/hgNear/hgNear.c
+++ src/hg/near/hgNear/hgNear.c
@@ -10,30 +10,35 @@
 #include "portable.h"
 #include "cheapcgi.h"
 #include "memalloc.h"
 #include "jksql.h"
 #include "htmshell.h"
 #include "hVarSubst.h"
 #include "cart.h"
 #include "dbDb.h"
 #include "hdb.h"
 #include "hui.h"
 #include "web.h"
 #include "ra.h"
 #include "hgColors.h"
 #include "hgNear.h"
 #include "versionInfo.h"
+#include "botDelay.h"
+
+/* for earlyBotCheck() function at the beginning of main() */
+#define delayFraction   1.0    /* standard penalty is 1.0 for most CGIs */
+static boolean issueBotWarning = FALSE;
 
 
 char *excludeVars[] = { "submit", "Submit", idPosVarName, NULL };
 /* The excludeVars are not saved to the cart. (We also exclude
  * any variables that start "near.do.") */
 
 /* ---- Global variables. ---- */
 struct cart *cart;	/* This holds cgi and other variables between clicks. */
 struct hash *oldVars = NULL; /* The cart vars before new cgi stuff added. */
 char *database;		/* Name of genome database - hg15, mm3, or the like. */
 char *genome;		/* Name of genome - mouse, human, etc. */
 char *groupOn;		/* Current grouping strategy. */
 int displayCount;	/* Number of items to display. */
 char *displayCountString; /* Ascii version of display count, including 'all'. */
 struct hash *genomeSettings;  /* Genome-specific settings from settings.ra. */
@@ -1870,30 +1875,37 @@
     database = defaultHgNearDb(genome);
     if (database == NULL)
 	errAbort("No databases are supporting hgNear.");
     genome = hGenome(database);
     cartSetString(cart, dbVarName, database);
     cartSetString(cart, orgVarName, genome);
     }
 }
 
 
 void doMiddle(struct cart *theCart)
 /* Write the middle parts of the HTML page.
  * This routine sets up some globals and then
  * dispatches to the appropriate page-maker. */
 {
+/* Using earlyBotCheck() at the beginning of main() to output message here if in delay time */
+if (issueBotWarning)
+    {
+    char *ip = getenv("REMOTE_ADDR");
+    botDelayMessage(ip, botDelayMillis);
+    }
+
 if (hIsBrowserbox())
     {
     printf("The Gene Sorter is not supported on the Genome Browser in a Box Virtual Machine.<p>");
     printf("Please use this tool on the <a href=\"http://genome.ucsc.edu/cgi-bin/hgNear\">UCSC website</a><p>");
     return;
     }
 
 char *var = NULL;
 struct sqlConnection *conn;
 struct column *colList, *col;
 cart = theCart;
 
 getDbAndGenome(cart, &database, &genome, oldVars);
 makeSureDbHasHgNear();
 getGenomeSettings();
@@ -1995,23 +2007,24 @@
 void usage()
 /* Explain usage and exit. */
 {
 errAbort(
   "hgNear - gene sorter - a cgi script\n"
   "usage:\n"
   "   hgNear\n"
   );
 }
 
 int main(int argc, char *argv[])
 /* Process command line. */
 {
 long enteredMainTime = clock1000();
 // pushCarefulMemHandler(100000000);
+issueBotWarning = earlyBotCheck(enteredMainTime, "hgNear", delayFraction, 0, 0, "html");
 cgiSpoof(&argc, argv);
 htmlSetStyle(htmlStyleUndecoratedLink);
 htmlSetBgColor(HG_CL_OUTSIDE);
 oldVars = hashNew(10);
 cartEmptyShell(doMiddle, hUserCookie(), excludeVars, oldVars);
 cgiExitTime("hgNear", enteredMainTime);
 return 0;
 }