659e1bb4271552d1d1056c529298fbccb039f95d hiram Sat Aug 17 08:29:32 2024 -0700 recording stats on results to stderr for apache error_log refs #32596 diff --git src/hg/hubApi/findGenome.c src/hg/hubApi/findGenome.c index b9328d5..3716fe8 100644 --- src/hg/hubApi/findGenome.c +++ src/hg/hubApi/findGenome.c @@ -35,31 +35,31 @@ | name | varchar(255) | NO | PRI | NULL | | | priority | int(10) unsigned | YES | | NULL | | | commonName | varchar(511) | YES | | NULL | | | scientificName | varchar(511) | YES | | NULL | | | taxId | int(10) unsigned | YES | | NULL | | | clade | varchar(255) | YES | | NULL | | | description | varchar(1023) | YES | | NULL | | | browserExists | tinyint(3) unsigned | YES | | NULL | | | hubUrl | varchar(511) | YES | | NULL | | +----------------+---------------------+------+-----+---------+-------+ */ static long long sqlJsonOut(struct jsonWrite *jw, struct sqlResult *sr) /* given a sqlResult, walk through the rows and output the json */ { -int itemCount = 0; +long long itemCount = 0; char **row; while ((row = sqlNextRow(sr)) != NULL) { struct assemblyList *el = assemblyListLoadWithNull(row); jsonWriteObjectStart(jw, el->name); jsonWriteNumber(jw, "priority", (long long)el->priority); jsonWriteString(jw, "commonName", el->commonName); jsonWriteString(jw, "scientificName", el->scientificName); jsonWriteNumber(jw, "taxId", (long long)el->taxId); jsonWriteString(jw, "clade", el->clade); jsonWriteString(jw, "description", el->description); if (1 == *el->browserExists) jsonWriteBoolean(jw, "browserExists", TRUE); else jsonWriteBoolean(jw, "browserExists", FALSE); @@ -171,42 +171,44 @@ /* add specific browserExists depending upon options */ if (browserMustExist) sqlDyStringPrintf(query, " AND browserExists=1"); else if (browserNotExist) sqlDyStringPrintf(query, " AND browserExists=0"); sqlDyStringPrintf(query, " ORDER BY priority LIMIT %d;", maxItemsOutput); struct sqlResult *sr = sqlGetResult(conn, query->string); itemCount = sqlJsonOut(jw, sr); sqlFreeResult(&sr); dyStringFree(&query); } return itemCount; } /* static long long oneWordSearch(struct sqlConnection *conn, char *searchWord, struct jsonWrite *jw, boolean *prefixSearch) */ -static void elapsedTime(struct jsonWrite *jw) +static long elapsedTime(struct jsonWrite *jw) { long nowTime = clock1000(); long elapsedTimeMs = nowTime - enteredMainTime; jsonWriteNumber(jw, "elapsedTimeMs", elapsedTimeMs); +return elapsedTimeMs; } void apiFindGenome(char *pathString[MAX_PATH_INFO]) /* 'findGenome' function */ { char *searchString = cgiOptionalString(argGenomeSearchTerm); char *inputSearchString = cloneString(searchString); +char *endResultSearchString = NULL; boolean prefixSearch = FALSE; char *extraArgs = verifyLegalArgs(argFindGenome); genarkTable = genarkTableName(); asmListTable = assemblyListTableName(); if (extraArgs) apiErrAbort(err400, err400Msg, "extraneous arguments found for function /findGenome'%s'", extraArgs); boolean asmListExists = hTableExists("hgcentraltest", asmListTable); if (!asmListExists) apiErrAbort(err400, err400Msg, "table hgcentraltest.assemblyList does not exist for /findGenome"); boolean asmSummaryExists = hTableExists("hgcentraltest", "asmSummary"); if (!asmSummaryExists) apiErrAbort(err400, err400Msg, "table hgcentraltest.asmSummary does not exist for /findGenome"); @@ -272,54 +274,60 @@ long long itemCount = 0; long long totalMatchCount = 0; char **words; AllocArray(words, wordCount); (void) chopByWhite(searchString, words, wordCount); if (1 == wordCount) itemCount = oneWordSearch(conn, words[0], jw, &totalMatchCount, &prefixSearch); else /* multiple word search */ itemCount = multipleWordSearch(conn, words, wordCount, jw, &totalMatchCount); if (prefixSearch) { struct dyString *addedStar = dyStringNew(64); dyStringPrintf(addedStar, "%s*", inputSearchString); - jsonWriteString(jw, argGenomeSearchTerm, dyStringCannibalize(&addedStar)); + endResultSearchString = dyStringCannibalize(&addedStar); + jsonWriteString(jw, argGenomeSearchTerm, endResultSearchString); } else + { + endResultSearchString = inputSearchString; jsonWriteString(jw, argGenomeSearchTerm, inputSearchString); + } /* rules about what can be in the search string: * + sign before a word indicates the word must be in the result * - sign before a word indicates it must not be in the result * * at end of word makes the word be a prefix search * "double quotes" to group words together as a phrase to match exactly * < or > adjust the words contribution to the relevance value * >moreImportant string); dyStringFree(&query); -elapsedTime(jw); +long elapTimeMs = elapsedTime(jw); +/* apache error_log recording */ +fprintf(stderr, "findGenome: '%s' found %lld returned %lld in %ld ms\n", endResultSearchString, totalMatchCount, itemCount, elapTimeMs); if (statsOnly) jsonWriteBoolean(jw, "statsOnly", TRUE); if (itemCount) { jsonWriteNumber(jw, "itemCount", itemCount); jsonWriteNumber(jw, "totalMatchCount", totalMatchCount); jsonWriteNumber(jw, "availableAssemblies", universeCount); if (totalMatchCount > itemCount) jsonWriteBoolean(jw, "maxItemsLimit", TRUE); apiFinishOutput(0, NULL, jw); } else apiErrAbort(err400, err400Msg, "no genomes found matching search term %s='%s' for endpoint: /findGenome", argGenomeSearchTerm, inputSearchString); hDisconnectCentral(&conn);