Browse Source

Fixed crash when closing qpasteWnd, When deleting clips i was deleting them all at the same time, locking the db, causing others to wait, killing a thread that was waiting was causing a crash

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@604 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 14 years ago
parent
commit
8af4b0de2b
5 changed files with 45 additions and 11 deletions
  1. 22 8
      DatabaseUtilities.cpp
  2. 14 1
      EventThread.cpp
  3. 2 2
      MainFrm.cpp
  4. 5 0
      Options.cpp
  5. 2 0
      Options.h

+ 22 - 8
DatabaseUtilities.cpp

@@ -384,9 +384,9 @@ BOOL BackupDB(CString dbPath, CString prefix)
 {
 	CString backup = GetFilePath(dbPath);
 
-	CInternetUpdate update;
-
-	long runningVersion = update.GetRunningVersion();
+	CInternetUpdate update;
+
+	long runningVersion = update.GetRunningVersion();
 	CString versionString = update.GetVersionString(runningVersion);
 
 	backup += GetFileName(dbPath) += _T("_") + prefix + _T("_") + versionString;
@@ -625,13 +625,27 @@ BOOL RemoveOldEntries()
 			}
 		}
 
-		Log(_T("Before Deleting emptied out data"));
+		int toDeleteCount = db.execScalar(_T("SELECT COUNT(clipID) FROM MainDeletes"));
+
+		Log(StrF(_T("Before Deleting emptied out data, count: %d"), toDeleteCount));
+
+		//Only delete 1 at a time, was finding that it was taking a long time to delete clips, locking the db and causing other queries
+		//to lock up
+		CppSQLite3Query q = db.execQueryEx(_T("SELECT * FROM MainDeletes LIMIT %d"), CGetSetOptions::GetMainDeletesDeleteCount());
+		int deleteCount = 0;
+
+		while(q.eof() == false)
+		{
+			//delete any data items sitting out there that the main table data was deleted
+			//this was done to speed up deleted from the main table
+			deleteCount = db.execDMLEx(_T("DELETE FROM MainDeletes WHERE clipID=%d"), q.getIntField(_T("clipID")));
+
+			q.nextRow();
+		}		
 
-		//delete any data items sitting out there that the main table data was deleted
-		//this was done to speed up deleted from the main table
-		int deleteCount = db.execDML(_T("DELETE FROM MainDeletes"));
+		toDeleteCount = db.execScalar(_T("SELECT COUNT(clipID) FROM MainDeletes"));
 
-		Log(StrF(_T("After Deleting emptied out data rows, Count: %d"), deleteCount));
+		Log(StrF(_T("After Deleting emptied out data rows, Count: %d, toDelete: %d"), deleteCount, toDeleteCount));
 	}
 	CATCH_SQLITE_EXCEPTION
 	

+ 14 - 1
EventThread.cpp

@@ -1,5 +1,6 @@
 #include "StdAfx.h"
 #include "EventThread.h"
+#include "Misc.h"
 
 #define EXIT_EVENT -1
 
@@ -7,7 +8,7 @@ CEventThread::CEventThread(void)
 {
 	AddEvent(EXIT_EVENT);
 	m_hEvt = CreateEvent(NULL, FALSE, FALSE, NULL);
-	m_waitTimeout = 1000;
+	m_waitTimeout = INFINITE;
 	m_threadRunning = false;
 	m_exitThread = false;
 }
@@ -97,6 +98,8 @@ void CEventThread::Start(void *param)
 
 void CEventThread::Stop(int waitTime) 
 {
+	Log(_T("Start of CEventThread::Stop(int waitTime) "));
+
 	if(m_threadRunning)
 	{
 		m_exitThread = true;	
@@ -106,15 +109,21 @@ void CEventThread::Stop(int waitTime)
 		{
 			if (WAIT_OBJECT_0 != WaitForSingleObject(m_hEvt, waitTime))
 			{
+				Log(_T("Start of TerminateThread CEventThread::Stop(int waitTime) "));
 				TerminateThread(m_thread, 0);
+				Log(_T("End of TerminateThread CEventThread::Stop(int waitTime) "));
 				m_threadRunning = false;
 			}
 		}
 	}
+
+	Log(_T("End of CEventThread::Stop(int waitTime) "));
 };
 
 void CEventThread::RunThread()
 {
+	Log(_T("Start of CEventThread::RunThread()"));
+
 	m_threadRunning = true;
 	HANDLE *pHandleArray = new HANDLE[m_eventMap.size()];
 
@@ -164,10 +173,14 @@ void CEventThread::RunThread()
 			}
 			else
 			{
+				Log(StrF(_T("Start of CEventThread::RunThread() - OnEvent %d"), eventId));
 				OnEvent(eventId, m_param);
+				Log(StrF(_T("End of CEventThread::RunThread() - OnEvent %d"), eventId));
 			}
 		}
 	}
 
+	Log(_T("Start of CEventThread::RunThread()"));
+
 	m_threadRunning = false;
 }

+ 2 - 2
MainFrm.cpp

@@ -144,9 +144,9 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
         }
     #endif 
 
-    SetTimer(CLOSE_WINDOW_TIMER, ONE_HOUR *24, 0);
+    SetTimer(CLOSE_WINDOW_TIMER, ONE_HOUR*24, 0);
     SetTimer(REMOVE_OLD_REMOTE_COPIES, ONE_DAY, 0);
-    SetTimer(REMOVE_OLD_ENTRIES_TIMER, ONE_MINUTE *15, 0);
+    SetTimer(REMOVE_OLD_ENTRIES_TIMER, ONE_MINUTE*15, 0);
 
     m_ulCopyGap = CGetSetOptions::GetCopyGap();
 

+ 5 - 0
Options.cpp

@@ -2007,4 +2007,9 @@ CString CGetSetOptions::GetCopyAppSeparator()
 DWORD CGetSetOptions::GetNoFormatsRetryDelay()
 {
 	return GetProfileLong(_T("NoFormatsRetryDelay"), 200);
+}
+
+DWORD CGetSetOptions::GetMainDeletesDeleteCount()
+{
+	return GetProfileLong(_T("MainDeletesDeleteCount"), 5);
 }

+ 2 - 0
Options.h

@@ -408,6 +408,8 @@ public:
 	static CString  GetCopyAppSeparator();
 
 	static DWORD	GetNoFormatsRetryDelay();
+
+	static DWORD	GetMainDeletesDeleteCount();
 };
 
 // global for easy access and for initialization of fast access variables