5538755f556a081861b4b715ca6cc70fbc49ec7c jcasper Fri Feb 24 16:36:25 2017 -0800 hgSession and PublicSessions should now work when gbMembers is remote, refs #18800 diff --git src/hg/hgSession/hgSession.c src/hg/hgSession/hgSession.c index da6157e..c16898d 100644 --- src/hg/hgSession/hgSession.c +++ src/hg/hgSession/hgSession.c @@ -814,103 +814,91 @@ "kent/src/hg/lib/namedSessionDb.sql .", namedSessionTable, sqlGetDatabase(conn)); hDisconnectCentral(&conn); return dyStringCannibalize(&dyMessage); } int thumbnailAdd(char *encUserName, char *encSessionName, struct sqlConnection *conn, struct dyString *dyMessage) /* Create a thumbnail image for the gallery. If the necessary tools can't be found, * add a warning message to dyMessage unless the hg.conf setting * sessionThumbnail.suppressWarning is set to "on". * Leaks memory from a generated filename string, plus a couple of dyStrings. * Returns without determining if image creation succeeded (it happens in a separate * thread); the return value is 0 if a message was added to dyMessage, otherwise it's 1. */ { char query[4096]; -char **row; -struct sqlResult *sr; char *suppressConvert = cfgOption("sessionThumbnail.suppress"); if (suppressConvert != NULL && sameString(suppressConvert, "on")) return 1; char *convertPath = cfgOption("sessionThumbnail.convertPath"); if (convertPath == NULL) convertPath = cloneString("convert"); char convertTestCmd[4096]; safef(convertTestCmd, sizeof(convertTestCmd), "which %s >& /dev/null", convertPath); int convertTestResult = system(convertTestCmd); if (convertTestResult != 0) { dyStringPrintf(dyMessage, "Note: A thumbnail image for this session was not created because the ImageMagick convert " "tool could not be found. Please contact your mirror administrator to resolve this " "issue, either by installing convert so that it is part of the webserver's PATH, " "by adding the \"sessionThumbnail.convertPath\" option to the mirror's hg.conf file " "to specify the path to that program, or by adding \"sessionThumbnail.suppress=on\" to " "the mirror's hg.conf file to suppress this warning.
"); return 0; } sqlSafef(query, sizeof(query), - "select m.idx, n.firstUse from gbMembers m join namedSessionDb n on m.userName = n.userName " - "where m.userName = \"%s\" and n.sessionName = \"%s\"", - encUserName, encSessionName); -sr = sqlGetResult(conn, query); -row = sqlNextRow(sr); -if (row == NULL) - errAbort("cannot add session to gallery; user %s, session %s", + "select firstUse from namedSessionDb where userName = \"%s\" and sessionName = \"%s\"", encUserName, encSessionName); - -char *destFile = sessionThumbnailFilePath(row[0], encSessionName, row[1]); +char *firstUse = sqlNeedQuickString(conn, query); +sqlSafef(query, sizeof(query), "select idx from gbMembers where userName = '%s'", encUserName); +char *userIdx = sqlQuickString(conn, query); +char *userIdentifier = sessionThumbnailGetUserIdentifier(encUserName, userIdx); +char *destFile = sessionThumbnailFilePath(userIdentifier, encSessionName, firstUse); if (destFile != NULL) { struct dyString *hgTracksUrl = dyStringNew(0); addSessionLink(hgTracksUrl, encUserName, encSessionName, FALSE); struct dyString *renderUrl = dyStringSub(hgTracksUrl->string, "cgi-bin/hgTracks", "cgi-bin/hgRenderTracks"); dyStringAppend(renderUrl, "&pix=640"); char *renderCmd[] = {"wget", "-q", "-O", "-", renderUrl->string, NULL}; char *convertCmd[] = {convertPath, "-", "-resize", "320", "-crop", "320x240+0+0", destFile, NULL}; char **cmdsImg[] = {renderCmd, convertCmd, NULL}; pipelineOpen(cmdsImg, pipelineWrite, "/dev/null", NULL); } -sqlFreeResult(&sr); return 1; } void thumbnailRemove(char *encUserName, char *encSessionName, struct sqlConnection *conn) /* Unlink thumbnail image for the gallery. Leaks memory from a generated filename string. */ { char query[4096]; -char **row; -struct sqlResult *sr; sqlSafef(query, sizeof(query), - "select m.idx, n.firstUse from gbMembers m join namedSessionDb n on m.userName = n.userName " - "where m.userName = \"%s\" and n.sessionName = \"%s\"", - encUserName, encSessionName); -sr = sqlGetResult(conn, query); -row = sqlNextRow(sr); -if (row == NULL) - errAbort("cannot remove session from gallery; user %s, session %s", + "select firstUse from namedSessionDb where userName = \"%s\" and sessionName = \"%s\"", encUserName, encSessionName); - -char *filePath = sessionThumbnailFilePath(row[0], encSessionName, row[1]); +char *firstUse = sqlNeedQuickString(conn, query); +sqlSafef(query, sizeof(query), "select idx from gbMembers where userName = '%s'", encUserName); +char *userIdx = sqlQuickString(conn, query); +char *userIdentifier = sessionThumbnailGetUserIdentifier(encUserName, userIdx); +char *filePath = sessionThumbnailFilePath(userIdentifier, encSessionName, firstUse); if (filePath != NULL) unlink(filePath); -sqlFreeResult(&sr); } char *doSessionDetail(char *userName, char *sessionName) /* Show details about a particular session. */ { if (userName == NULL) return "Sorry, please log in again."; struct dyString *dyMessage = dyStringNew(4096); char *encSessionName = cgiEncodeFull(sessionName); char *encUserName = cgiEncodeFull(userName); struct sqlConnection *conn = hConnectCentral(); struct sqlResult *sr = NULL; char **row = NULL; char query[512]; webPushErrHandlersCartDb(cart, cartUsualString(cart, "db", NULL));