Browse Source

check idle time before deleting clips from the db

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@605 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 14 years ago
parent
commit
8513a8a3b6
7 changed files with 98 additions and 53 deletions
  1. 16 4
      DatabaseUtilities.cpp
  2. 7 1
      EventThread.cpp
  3. 12 1
      Misc.cpp
  4. 2 0
      Misc.h
  5. 12 2
      Options.cpp
  6. 4 0
      Options.h
  7. 45 45
      StdAfx.h

+ 16 - 4
DatabaseUtilities.cpp

@@ -212,6 +212,8 @@ BOOL OpenDatabase(CString csDB)
 		theApp.m_db.open(csDB);
 		CGetSetOptions::SetDBPath(csDB);
 
+		theApp.m_db.setBusyTimeout(CGetSetOptions::GetDbTimeout());
+
 		return TRUE;
 	}
 	CATCH_SQLITE_EXCEPTION
@@ -627,7 +629,7 @@ BOOL RemoveOldEntries()
 
 		int toDeleteCount = db.execScalar(_T("SELECT COUNT(clipID) FROM MainDeletes"));
 
-		Log(StrF(_T("Before Deleting emptied out data, count: %d"), toDeleteCount));
+		Log(StrF(_T("Before Deleting emptied out data, count: %d, Idle Seconds: %d"), toDeleteCount, IdleSeconds()));
 
 		//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
@@ -636,10 +638,20 @@ BOOL RemoveOldEntries()
 
 		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")));
+			DWORD idleSeconds = IdleSeconds();
+			if(idleSeconds > CGetSetOptions::GetIdleSecondsBeforeDelete())
+			{
+				//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")));
+			}
+			else
+			{
+				Log(StrF(_T("Computer has not been idle long enough to delete clips, Min Idle: %d, current Idle: %d"), 
+												CGetSetOptions::GetIdleSecondsBeforeDelete(), idleSeconds));
 
+				break;
+			}
 			q.nextRow();
 		}		
 

+ 7 - 1
EventThread.cpp

@@ -38,6 +38,10 @@ void CEventThread::AddEvent(int eventId)
 
 bool CEventThread::FireEvent(int eventId)
 {
+	//Log(StrF(_T("Begin FireEvent, eventId: %d"), eventId));
+
+	bool ret = false;
+
 	HANDLE eventHandle = NULL;
 	for(EventMapType::iterator it = m_eventMap.begin(); it != m_eventMap.end(); it++)
 	{
@@ -51,9 +55,11 @@ bool CEventThread::FireEvent(int eventId)
 	if(eventHandle != NULL)
 	{
 		SetEvent(eventHandle);
-		return true;
+		ret = true;
 	}
 	
+	//Log(StrF(_T("End FireEvent, eventId: %d"), eventId));
+
 	return false;
 }
 

+ 12 - 1
Misc.cpp

@@ -71,7 +71,7 @@ void log(const TCHAR* msg, bool bFromSendRecieve, CString csFile, long lLine)
 	ASSERT(AfxIsValidString(msg));
 
 	SYSTEMTIME st;
-	GetSystemTime(&st);
+	GetLocalTime(&st);
 	
 	CString	csText;
 	csText.Format(_T("[%d/%d/%d %02d:%02d:%02d.%03d - "), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
@@ -132,6 +132,17 @@ CString GetErrorString( int err )
 	return str;
 }
 
+DWORD IdleSeconds()
+{
+	LASTINPUTINFO info; 
+	info.cbSize = sizeof(info);
+	GetLastInputInfo(&info);   
+	ULONGLONG currentTick  = GetTickCount64();
+	DWORD idleSeconds = (currentTick - info.dwTime)/1000;
+
+	return idleSeconds;
+}
+
 CString StrF(const TCHAR * pszFormat, ...)
 {
 	ASSERT( AfxIsValidString( pszFormat ) );

+ 2 - 0
Misc.h

@@ -51,6 +51,8 @@ void AppendToFile(const TCHAR* fn, const TCHAR *msg);
 void log(const TCHAR* msg, bool bFromSendRecieve = false, CString csFile = _T(""), long lLine = -1);
 CString GetErrorString(int err);
 
+DWORD IdleSeconds();
+
 #define LogSendRecieveInfo(cs) logsendrecieveinfo(cs, __FILE__, __LINE__)
 void logsendrecieveinfo(CString cs, CString csFile = _T(""), long lLine = -1);
 

+ 12 - 2
Options.cpp

@@ -2010,6 +2010,16 @@ DWORD CGetSetOptions::GetNoFormatsRetryDelay()
 }
 
 DWORD CGetSetOptions::GetMainDeletesDeleteCount()
-{
-	return GetProfileLong(_T("MainDeletesDeleteCount"), 5);
+{  
+	return GetProfileLong(_T("MainDeletesDeleteCount"), 100);
+}
+
+DWORD CGetSetOptions::GetIdleSecondsBeforeDelete()
+{  
+	return GetProfileLong(_T("IdleSecondsBeforeDelete"), 60*10);
+}
+
+DWORD CGetSetOptions::GetDbTimeout()
+{  
+	return GetProfileLong(_T("DbTimeout"), 5000);
 }

+ 4 - 0
Options.h

@@ -410,6 +410,10 @@ public:
 	static DWORD	GetNoFormatsRetryDelay();
 
 	static DWORD	GetMainDeletesDeleteCount();
+
+	static DWORD	GetIdleSecondsBeforeDelete();
+
+	static DWORD	GetDbTimeout();
 };
 
 // global for easy access and for initialization of fast access variables

+ 45 - 45
StdAfx.h

@@ -1,46 +1,46 @@
-// stdafx.h : include file for standard system include files,
-//  or project specific include files that are used frequently, but
-//      are changed infrequently
-//
-
-#if !defined(AFX_STDAFX_H__56F3D184_7208_47FE_AFE2_E270325F356A__INCLUDED_)
-#define AFX_STDAFX_H__56F3D184_7208_47FE_AFE2_E270325F356A__INCLUDED_
-
-#if _MSC_VER > 1000
-#pragma once
-#endif // _MSC_VER > 1000
-
-#pragma warning(disable : 4995)
-
-//remove 2005 warnings
-#define _CRT_SECURE_NO_DEPRECATE 1
-#define _CRT_NON_CONFORMING_SWPRINTFS 1
-
-#define HITTEST_RET LRESULT
-
-#define _WIN32_WINNT 0x0500
-#define WINVER 0x0500
-
-#define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers
-
-#include <afxwin.h>         // MFC core and standard components
-#include <afxext.h>         // MFC extensions
-#include <afxdisp.h>        // MFC Automation classes
-#include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
-#ifndef _AFX_NO_AFXCMN_SUPPORT
-#include <afxcmn.h>			// MFC support for Windows Common Controls
-#endif // _AFX_NO_AFXCMN_SUPPORT
-#include <afxole.h>
-#include <Winsock2.h>
-
-#include "UnicodeMacros.h"
-
-#include <imm.h>
+// stdafx.h : include file for standard system include files,
+//  or project specific include files that are used frequently, but
+//      are changed infrequently
+//
+
+#if !defined(AFX_STDAFX_H__56F3D184_7208_47FE_AFE2_E270325F356A__INCLUDED_)
+#define AFX_STDAFX_H__56F3D184_7208_47FE_AFE2_E270325F356A__INCLUDED_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif // _MSC_VER > 1000
+
+#pragma warning(disable : 4995)
+
+//remove 2005 warnings
+#define _CRT_SECURE_NO_DEPRECATE 1
+#define _CRT_NON_CONFORMING_SWPRINTFS 1
+
+#define HITTEST_RET LRESULT
+
+#define _WIN32_WINNT 0x0600
+#define WINVER 0x0600
+
+#define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers
+
+#include <afxwin.h>         // MFC core and standard components
+#include <afxext.h>         // MFC extensions
+#include <afxdisp.h>        // MFC Automation classes
+#include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
+#ifndef _AFX_NO_AFXCMN_SUPPORT
+#include <afxcmn.h>			// MFC support for Windows Common Controls
+#endif // _AFX_NO_AFXCMN_SUPPORT
+#include <afxole.h>
+#include <Winsock2.h>
+
+#include "UnicodeMacros.h"
+
+#include <imm.h>
 #include <afxcontrolbars.h>
-#import "riched20.dll" raw_interfaces_only, raw_native_types, no_namespace, named_guids, exclude("UINT_PTR"), exclude("LONG_PTR") 
-
-
-//{{AFX_INSERT_LOCATION}}
-// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
-
-#endif // !defined(AFX_STDAFX_H__56F3D184_7208_47FE_AFE2_E270325F356A__INCLUDED_)
+#import "riched20.dll" raw_interfaces_only, raw_native_types, no_namespace, named_guids, exclude("UINT_PTR"), exclude("LONG_PTR") 
+
+
+//{{AFX_INSERT_LOCATION}}
+// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
+
+#endif // !defined(AFX_STDAFX_H__56F3D184_7208_47FE_AFE2_E270325F356A__INCLUDED_)