ce90ee5ec5f7377937451a8c8eb93a7dc33731de
galt
  Tue Apr 22 13:56:24 2025 -0700
hgcentralTidy.c cleaner - added -skipDel option and verbose=4 for seeing sql delete statements detail. dryRun skips too many details.

diff --git src/hg/hgcentralTidy/hgcentralTidy.c src/hg/hgcentralTidy/hgcentralTidy.c
index 435669b4905..41592626cf3 100644
--- src/hg/hgcentralTidy/hgcentralTidy.c
+++ src/hg/hgcentralTidy/hgcentralTidy.c
@@ -41,45 +41,47 @@
 void usage()
 /* Explain usage and exit. */
 {
 errAbort(
   "hgcentralTidy - Clean out old carts in hgcentral without blocking cart use\n"
   "usage:\n"
   "   hgcentralTidy config\n"
   "options:\n"
   "   -chunkSize=N - number of rows to examine in one chunk, default %d\n"
   "   -chunkWait=N - sleep interval between chunks to allow other processing, default %d'\n"
   "   -squealSize=N - email warning to cluster-admin when this size in GB is exceeded, default %d'\n"
   "   -purgeStart=N - purge range starts N days ago'\n"
   "   -purgeEnd=N - purge range end N days ago'\n"
   "   -purgeTable=tableName - optional purge table must be userDb or sessionDb. If not specified, both tables are purged.'\n"
   "   -dryRun - option that causes it to skip the call to cleanTableSection.'\n"
+  "   -skipDel - option that causes it to skip the delete returning counts from skipped deletes.'\n"
   , chunkSize
   , chunkWait
   , squealSize
   );
 }
 
 
 static struct optionSpec options[] = {
    {"chunkSize", OPTION_INT},
    {"chunkWait", OPTION_INT},
    {"squealSize", OPTION_INT},
    {"purgeStart", OPTION_INT},
    {"purgeEnd", OPTION_INT},
    {"purgeTable", OPTION_STRING},
    {"dryRun", OPTION_STRING},
+   {"skipDel", OPTION_BOOLEAN},
    {NULL, 0},
 };
 
 char *getCfgOption(char *config, char *setting)
 /* get setting for specified config */
 {
 char temp[256];
 safef(temp, sizeof(temp), "%s.%s", config, setting);
 char *value = cfgOption(temp);
 if (!value)
     errAbort("setting %s not found!",temp);
 return value;
 }
 
 
@@ -243,53 +245,64 @@
     		, useCount 
     		);
 	    slAddHead(&delList, slUnsignedNew(maxId));
 	    }
 
 	}
     sqlFreeResult(&sr);
    
     if (rc < 1)
 	    break;
 
     if (dc > 0)
 	{
 	struct slUnsigned *i;
 	for (i=delList;i;i=i->next)
+	    {
+            if (!optionExists("skipDel"))
 		{
 		dyStringClear(dy); 
 	        sqlDyStringPrintf(dy, "delete from %s where id=%u", table, i->val);
 		sqlUpdate(conn,dy->string);
 		}
+	    else  // GALT DEBUG REMOVE
+		{
+		dyStringClear(dy); 
+	        sqlDyStringPrintf(dy, "delete from %s where id=%u", table, i->val);
+		verbose(4,"GALT DEBUG del dystring = [%s]\n", dy->string);
+		}
+
+	    }
 	slFreeList(&delList);
 	}
  
     delCount+=dc;
   
     if (maxId >= endId)
 	{
 	break;  // we have done enough
 	}
 
     	
     verbose(3, "sleeping %d seconds\n", chunkWait);fflush(stderr);
     sleep(chunkWait);
     verbose(3, "awake\n");fflush(stderr);
 
     }
 
-    verbose(1, "old recs deleted %d, robot recs deleted %d\n", oldRecCount, delRobotCount);fflush(stderr);
+    verbose(1, "old recs %s deleted %d, robot recs %s deleted %d\n", optionExists("skipDel")?"would have been":"", oldRecCount,
+         optionExists("skipDel")?"would have been":"", delRobotCount);fflush(stderr);
 
     time_t cleanEnd = time(NULL);
     int minutes = difftime(cleanEnd, cleanSectionStart) / 60; 
     verbose(1, "%s\n", ctime(&cleanEnd));
     verbose(1, "%d minutes\n\n", minutes);
 }
 
 int binaryIdSearch(unsigned int *ids, int numIds, char *table, int daysAgo)
 /* Find the array index in ids which holds the id that contains
  * the oldest record satisfying the daysAgo criterion. 
  * If not found, return -1 */
 {
 char query[256];
 int a = 0;
 int b = numIds - 1;