3a149415fde399e02345bf9fcbf8aadd0f0c1baa
tdreszer
  Fri Feb 25 10:12:30 2011 -0800
File search can get terribly slow with too many files.  Limit to 1000.
diff --git src/hg/lib/fileUi.c src/hg/lib/fileUi.c
index 2ae0a26..70662ab 100644
--- src/hg/lib/fileUi.c
+++ src/hg/lib/fileUi.c
@@ -669,81 +669,85 @@
 struct sqlConnection *connLocal = conn;
 if (conn == NULL)
     connLocal = hAllocConn(db);
 struct mdbObj *mdbList = mdbObjRepeatedSearch(connLocal,varValPairs,FALSE,TRUE);
 if (conn == NULL)
     hFreeConn(&connLocal);
 if (slCount(mdbList) == 0)
     {
     printf("<DIV id='filesFound'><BR>No files found.<BR></DIV><BR>\n");
     return 0;
     }
 
 // Now sort mdbObjs so that composites will stay together and lookup of files will be most efficient
 mdbObjsSortOnVars(&mdbList, "composite");
 
+#define FOUND_FILE_LIMIT 1000
+int fileCount = 0;
 // Verify file existance and make fileList of those found
 struct fileDb *fileList = NULL, *oneFile = NULL; // Will contain found files
 struct mdbObj *mdbFiles = NULL; // Will caontain a list of mdbs for the found files
-while(mdbList)
+while(mdbList && fileCount < FOUND_FILE_LIMIT)
     {
     boolean found = FALSE;
     struct mdbObj *mdbFile = slPopHead(&mdbList);
     char *composite = mdbObjFindValue(mdbFile,"composite");
     if (composite != NULL)
         {
         // First for FileName
         char *fileName = mdbObjFindValue(mdbFile,"fileName");
         if (fileName != NULL)
             {
             oneFile = fileDbGet(db, ENCODE_DCC_DOWNLOADS, composite, fileName);
             if (oneFile)
                 {
                 //warn("%s == %s",fileType,oneFile->fileType);
                 if (isEmpty(fileType) || sameWord(fileType,"Any")
                 || (oneFile->fileType && sameWord(fileType,oneFile->fileType)))
                     {
                     slAddHead(&fileList,oneFile);
                     oneFile->mdb = mdbFile;
                     slAddHead(&mdbFiles,mdbFile);
+                    fileCount++;
                     found = TRUE;
                     continue;
                     }
                 }
                 else
                     fileDbFree(&oneFile);
             }
         // Now for FileIndexes
         fileName = mdbObjFindValue(mdbFile,"fileIndex");
         if (fileName != NULL)
             {
            // Verify existance first
             oneFile = fileDbGet(db, ENCODE_DCC_DOWNLOADS, composite, fileName);
             if (oneFile)
                 {
                 //warn("%s == %s",fileType,oneFile->fileType);
                 if (isEmpty(fileType) || sameWord(fileType,"Any")
                 || (oneFile->fileType && sameWord(fileType,oneFile->fileType)))
                    {
                     slAddHead(&fileList,oneFile);
                     if (found) // if already found then need two mdbObjs (assertable but then this is metadata)
                         oneFile->mdb = mdbObjClone(mdbFile);  // Do we really need to clone this?
                     else
                         {
                         oneFile->mdb = mdbFile;
                         slAddHead(&mdbFiles,mdbFile);
                         }
+                    fileCount++;
                     found = TRUE;
                     continue;
                     }
                 else
                     fileDbFree(&oneFile);
                 }
             }
         }
     if (!found)
         mdbObjsFree(&mdbFile);
     }
 if (slCount(fileList) == 0)
     {
     printf("<DIV id='filesFound'><BR>No files found.<BR></DIV><BR>\n");
     return 0;  // No files so nothing to do.
@@ -753,22 +757,30 @@
 //// Now update all files with their sortable fields and sort the list
 sortOrder_t *sortOrder = fileSortOrderGet(NULL,NULL,mdbFiles); // No cart, no tdb
 if (sortOrder != NULL)
     {
     // Fill in and sort fileList
     fileDbSortList(&fileList,sortOrder);
     }
 
 mdbObjRemoveVars(mdbFiles,"tableName"); // Remove this from mdb now so that it isn't displayed in "extras'
 
 //jsIncludeFile("hui.js",NULL);
 //jsIncludeFile("ajax.js",NULL);
 
 // Print table
 printf("<DIV id='filesFound'>");
-int filesCount = filesPrintTable(db,NULL,fileList,sortOrder);
+if (mdbList != NULL)
+    {
+    printf("<DIV class='redBox' style='width: 380px;'>Too many files found.  Displaying first %d of potentially %d.<BR>Narrow search parameters and try again.</DIV><BR>\n",
+           fileCount,(fileCount+slCount(mdbList)*2)); // Multiply*2 because of fileIndexes
+    //warn("Too many files found.  Displaying first %d of potentially %d.<BR>Narrow search parameters and try again.\n", fileCount,(fileCount+slCount(mdbList)*2)); // Multiply because of fileIndexes
+    mdbObjsFree(&mdbList);
+    }
+
+fileCount = filesPrintTable(db,NULL,fileList,sortOrder);
 printf("</DIV><BR>\n");
 
 //fileDbFree(&fileList); // Why bother on this very long running cgi?
-return filesCount;
+return fileCount;
 }