示例#1
0
bool BigThread(int iParentID, int iThreadID)
{
   int iNumMessages = 0, iMessageID = -1, iLength = 0;
   double dTick = gettick();
   char szSQL[200];
   DBTable *pMessages = NULL;
   Message *pMessage = NULL;
   list<Message *> pList;
   
   // printf("BigThread entry %d %d\n", iParentID, iThreadID);
   
   pMessages = new DBTable();
   pMessages->BindColumnInt();
   pMessages->BindColumnInt();
   
   sprintf(szSQL, "select messageid,length(message_text) from folder_message_item where parentid=%d", iParentID);
   // printf("BigThread running '%s'\n", szSQL);
   if(pMessages->Execute(szSQL) == false)
   {
      printf("BigThread exit false, query '%s' failed\n", szSQL);
      
      delete pMessages;
	
      return false;
   }
   // printf("BigThread query run (%ld ms)\n", tickdiff(dTick));
   
   while(pMessages->NextRow() == true)
   {
      iNumMessages++;
				
      pMessages->GetField(0, &iMessageID);
      pMessages->GetField(1, &iLength);
      // printf("BigThread %d %d\n", iMessageID, iLength);
      
      pMessage = new Message();
      pMessage->m_iID = iMessageID;
      pMessage->m_iSize = iLength;
      
      pList.push_back(pMessage);
      
      pMessage = MessageGet(iThreadID, false);
      // printf("BigThread %p\n", pMessage);
      pMessage->m_iCount++;
      pMessage->m_iSize += iLength;
   }
   
   delete pMessages;
   
   while(pList.empty() == false)
   {
      pMessage = pList.front();
      BigThread(pMessage->m_iID, iThreadID);
      
      pList.pop_front();
   }
   
   // printf("BigThread exit true, %d messages\n", iNumMessages);
   return true;
}
示例#2
0
bool BigThreads(int iFolderID, int iLimit)
{
   STACKTRACE
   int iNumThreads = 0, iThreadNum = 0, iMessageID = -1, iFromID = -1;
   double dTick = gettick();
   char *szSubject = NULL;
   char szSQL[200];
   DBTable *pThreads = NULL;
   Message *pMessage = NULL, *pThreadList = NULL;
   map<int, Message>::const_iterator pThreadIter;
   
   printf("BigThreads entry %d\n", iFolderID);
   
   pThreads = new DBTable();
   pThreads->BindColumnInt();
   pThreads->BindColumnInt();
   pThreads->BindColumnBytes();

   sprintf(szSQL, "select messageid,fromid,subject from folder_message_item where parentid=-1");
   if(iFolderID != -1)
   {
      sprintf(szSQL, "%s and folderid=%d", szSQL, iFolderID);
   }
   else
   {
      strcat(szSQL, " and folderid <> 384");
   }
   strcat(szSQL, " order by messageid");

   if(pThreads->Execute(szSQL) == false)
   {
      delete pThreads;

      printf("BigThreads exit false, query '%s' failed\n", szSQL);
      return false;
   }
   printf("BigThreads query run (%ld ms)\n", tickdiff(dTick));

   while(pThreads->NextRow() == true)
   {
      if(iNumThreads > 0 && iNumThreads % 100 == 0)
      {
	 printf("BigThreads querying %dth thread\n", iNumThreads);
      }
	   
      iNumThreads++;
      
      pThreads->GetField(0, &iMessageID);
      pThreads->GetField(1, &iFromID);
      pThreads->GetField(2, &szSubject);
      
      // printf("BigThreads query message %d %s\n", iMessageID, szSubject);
      
      pMessage = MessageGet(iMessageID, true);
      pMessage->m_iFromID = iFromID;
      pMessage->m_szSubject = strmk(szSubject);
      
      szSubject = NULL;
   }

   delete pThreads;
   
   printf("BigThreads %d threads\n", iNumThreads);
   
   pThreadList = new Message[iNumThreads];

   pThreadIter = g_pMessages.begin();
   while(pThreadIter != g_pMessages.end())
   {
      if(iThreadNum > 0 && iThreadNum % 100 == 0)
      {
	 printf("BigThreads processing %dth of %d threads\n", iThreadNum, iNumThreads);
      }
      
      pMessage = (Message *)&pThreadIter->second;
      
      BigThread(pMessage->m_iID, pMessage->m_iID);

      pThreadList[iThreadNum] = *pMessage;
      
      pThreadIter++;
      iThreadNum++;
   }
   
   g_iSortType = SORT_COUNT;
   qsort(pThreadList, iNumThreads, sizeof(Message), SortThreads);
   
   if(iLimit == 0 || iLimit > iNumThreads)
   {
      iLimit = iNumThreads;
   }
   
   printf("BigThreads biggest %d threads:\n", iLimit);
   
   for(iThreadNum = 0; iThreadNum < iLimit; iThreadNum++)
   {
      pMessage = &pThreadList[iThreadNum];
	
      printf("BigThreads thread %d(from %d, %s), %d messages (total size %d bytes)\n", pMessage->m_iID, pMessage->m_iFromID, pMessage->m_szSubject, pMessage->m_iCount, pMessage->m_iSize);
   }
   
   printf("BigThreads exit true, %d threads\n", iNumThreads);
   return true;
}
示例#3
0
int main(int argc, char **argv)
{
   int iDebugLevel = 0, iNumMsgs = 0;
   long lMessageID = -1, lParentID = -1, lFolderID = -1, lDate = 0, lFromID = -1, lToID = -1;
   char *szSQL = NULL;
   bytes *pText = NULL, *pSubject = NULL, *pEDF = NULL;
   EDF *pSearch = NULL;
   DBTable *pTable = NULL;
   double dTick = 0;

   if(argc != 3 || !(strcmp(argv[1], "-edf") == 0 || strcmp(argv[1], "-query") == 0))
   {
      printf("Usage: Searching -edf <file>\n");
      printf("Usage: Searching -query <string>\n");

      return 1;
   }

   if(strcmp(argv[1], "-edf") == 0)
   {
      pSearch = EDFParser::FromFile(argv[2]);
      if(pSearch == NULL)
      {
         printf("Could not parse %s, %s\n", argv[2], strerror(errno));
         return 1;
      }

      EDFParser::Print("Search", pSearch);
   }
   else
   {
      pSearch = QueryToEDF(argv[2]);

      printf("Query %s\n", argv[2]);
      EDFParser::Print("Search", pSearch);

      // return 0;
   }
   printf("\n");

   dTick = gettick();
   szSQL = MessageSQL(pSearch);
   printf("SQL(%ld ms): %s\n", tickdiff(dTick), szSQL);
   if(szSQL == NULL)
   {
      printf("Nothing to search for\n");

      return 1;
   }

   if(DBTable::Connect("ua27") == false)
   {
      printf("Cannot connect to database, %s\n", strerror(errno));

      delete pSearch;

      return 1;
   }

   pTable = new DBTable();

   printf("Binding columns\n");

   // messageid
   pTable->BindColumnInt();

   // parentid
   pTable->BindColumnInt();

   // treeid, date, fromid, toid, text
   pTable->BindColumnInt();
   pTable->BindColumnInt();
   pTable->BindColumnInt();
   pTable->BindColumnInt();
   pTable->BindColumnBytes();

   // subject
   pTable->BindColumnBytes();

   // edf
   pTable->BindColumnBytes();

   dTick = gettick();
   printf("Running query\n");
   if(pTable->Execute(szSQL) == true)
   {
      printf("Execute(%ld ms)\n", tickdiff(dTick));

      // iDebugLevel = debuglevel(DEBUGLEVEL_DEBUG);

      dTick = gettick();

      while(pTable->NextRow() == true)
      {
         iNumMsgs++;

         lMessageID = -1;

         lParentID = -1;

         lFolderID = -1;
         lDate = 0;
         lFromID = -1;
         lToID = -1;
         pText = NULL;

         pSubject = NULL;

         pEDF = NULL;

         // messageid
         pTable->GetField(0, &lMessageID);

         // parentid
         pTable->GetField(1, &lParentID);

         // treeid, date, fromid, toid, text
         pTable->GetField(2, &lFolderID);
         pTable->GetField(3, &lDate);
         pTable->GetField(4, &lFromID);
         pTable->GetField(5, &lToID);
         pTable->GetField(6, &pText);

         // subject
         pTable->GetField(7, &pSubject);

         // edf
         pTable->GetField(7, &pEDF);

         printf("m=%ld p=%ld f=%ld d=%ld %ld %ld", lMessageID, lParentID, lFolderID, lDate, lFromID, lToID);
         if(pSubject != NULL)
         {
            printf(", %s", (char *)pSubject->Data(false));
         }
         if(pText != NULL)
         {
            printf(":\n%s", (char *)pText->Data(false));
         }
         printf("\n");

         // delete pEDF;
         // delete pSubject;
         // delete pText;
      }

      // debuglevel(iDebugLevel);

      printf("Found %d messages(%ld ms)\n", iNumMsgs, tickdiff(dTick));
   }
   else
   {
      printf("Query failed, %s\n", strerror(errno));
   }

   delete pTable;

   DBTable::Disconnect();

   delete[] szSQL;

   delete pSearch;

   return 0;
}