783eee083cb8f18c4235ce6655e0f6bc18c09d5e max Thu Apr 24 04:48:00 2025 -0700 making hgcentraltidy more aggressive for single use userDb rows, refs #35554 diff --git src/hg/hgcentralTidy/hgcentralTidy.c src/hg/hgcentralTidy/hgcentralTidy.c index 435669b4905..39593494bf0 100644 --- src/hg/hgcentralTidy/hgcentralTidy.c +++ src/hg/hgcentralTidy/hgcentralTidy.c @@ -158,31 +158,33 @@ int useCount = 0; boolean deleteThis = FALSE; int delRobotCount = 0; int oldRecCount = 0; struct slUnsigned *delList = NULL; time_t cleanSectionStart = time(NULL); struct dyString *dy = dyStringNew(0); while(TRUE) { verbose(2, "maxId: %u count=%d delCount=%d dc=%d\n", maxId, count, delCount, dc); sqlSafef(query,sizeof(query), "select id, firstUse, lastUse, useCount from %s" - " where id > %u order by id limit %d" + " where id > %u " + " AND lastUse < NOW() - INTERVAL 1 HOUR" + " order by id limit %d;" , table , maxId , chunkSize ); sr = sqlGetResult(conn, query); rc = 0; dc = 0; dyStringClear(dy); while ((row = sqlNextRow(sr)) != NULL) { ++count; ++rc; maxId = sqlUnsigned(row[0]); useCount = sqlSigned(row[3]); @@ -208,31 +210,34 @@ } else if ((daysAgoFirstUse >= 2) && useCount <= 1) /* reasonable new addition */ { deleteThis = TRUE; ++delRobotCount; } } if (sameString(table, userDbTableName)) { if ((daysAgoFirstUse >= 7) && useCount < 7) { deleteThis = TRUE; ++delRobotCount; } - else if ((daysAgoFirstUse >= 2) && useCount <= 1) + /* some botnets have hgsid but do not store cookies -> useCount is always 1 */ + /* Since we excluded rows that are from the last 1 hour, this will not delete anything */ + /* from human users who just came to the site before this program ran */ + else if (useCount <= 1) { deleteThis = TRUE; ++delRobotCount; } else if (daysAgoLastUse >= 365) /* reasonable new addition */ { deleteThis = TRUE; ++oldRecCount; } } if (deleteThis) { ++dc; verbose(3, "TO DELETE id: %u, "