X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fdbmaintenancethread.cpp;h=ae4dc88357955f545fdae5cceafa063587788241;hb=e662ea47fba8715474851ceebacba400984ee433;hp=f8c33571e3e3a7f139b10a40a303cf40ac5cfe3c;hpb=d5c9f7e6c1dd263dfc85a3cb5941a378a5ddd923;p=fms.git diff --git a/src/dbmaintenancethread.cpp b/src/dbmaintenancethread.cpp index f8c3357..ae4dc88 100644 --- a/src/dbmaintenancethread.cpp +++ b/src/dbmaintenancethread.cpp @@ -1,6 +1,8 @@ #include "../include/dbmaintenancethread.h" #include "../include/stringfunctions.h" #include "../include/option.h" +#include "../include/threadbuilder.h" +#include "../include/dbsetup.h" #include #include @@ -35,13 +37,89 @@ DBMaintenanceThread::DBMaintenanceThread() void DBMaintenanceThread::Do10MinuteMaintenance() { + std::string ll=""; + Option::Instance()->Get("LogLevel",ll); + + // TODO - remove after corruption issue fixed + if(ll=="8") + { + std::string dbres=TestDBIntegrity(); + m_log->trace("DBMaintenanceThread::Do10MinuteMaintenance() start TestDBIntegrity returned "+dbres); + } + + ThreadBuilder tb; + SQLite3DB::Statement boardst=m_db->Prepare("SELECT BoardID FROM tblBoard WHERE Forum='true';"); + // select messages for a board that aren't in a thread + SQLite3DB::Statement selectst=m_db->Prepare("SELECT tblMessage.MessageID FROM tblMessage \ + INNER JOIN tblMessageBoard ON tblMessage.MessageID=tblMessageBoard.MessageID\ + LEFT JOIN tblThreadPost ON tblMessage.MessageID=tblThreadPost.MessageID \ + LEFT JOIN tblThread ON tblThreadPost.ThreadID=tblThread.ThreadID\ + WHERE tblMessageBoard.BoardID=? AND tblThread.BoardID IS NULL;"); + + boardst.Step(); + while(boardst.RowReturned()) + { + int boardid=-1; + + boardst.ResultInt(0,boardid); + + selectst.Bind(0,boardid); + selectst.Step(); + + while(selectst.RowReturned()) + { + int messageid=-1; + + selectst.ResultInt(0,messageid); + + tb.Build(messageid,boardid,true); + + selectst.Step(); + } + selectst.Reset(); + + boardst.Step(); + } + + // TODO - remove after corruption issue fixed + if(ll=="8") + { + std::string dbres=TestDBIntegrity(); + m_log->trace("DBMaintenanceThread::Do10MinuteMaintenance() middle TestDBIntegrity returned "+dbres); + } + + // now rebuild threads where the message has been deleted + SQLite3DB::Statement st=m_db->Prepare("SELECT tblThreadPost.MessageID, tblThread.BoardID FROM tblThreadPost INNER JOIN tblThread ON tblThreadPost.ThreadID=tblThread.ThreadID LEFT JOIN tblMessage ON tblThreadPost.MessageID=tblMessage.MessageID WHERE tblMessage.MessageID IS NULL;"); + st.Step(); + while(st.RowReturned()) + { + int messageid=-1; + int boardid=-1; + + st.ResultInt(0,messageid); + st.ResultInt(1,boardid); + + tb.Build(messageid,boardid,true); + + st.Step(); + } + + // delete threads that have no messages + m_db->Execute("DELETE FROM tblThread WHERE ThreadID IN (SELECT tblThread.ThreadID FROM tblThread LEFT JOIN tblThreadPost ON tblThread.ThreadID=tblThreadPost.ThreadID WHERE tblThreadPost.ThreadID IS NULL);"); + + // TODO - remove after corruption issue fixed + if(ll=="8") + { + std::string dbres=TestDBIntegrity(); + m_log->trace("DBMaintenanceThread::Do10MinuteMaintenance() end TestDBIntegrity returned "+dbres); + } m_log->debug("PeriodicDBMaintenance::Do10MinuteMaintenance"); } void DBMaintenanceThread::Do30MinuteMaintenance() { - + // UNCOMMENT method in run when code is placed here m_log->debug("PeriodicDBMaintenance::Do30MinuteMaintenance"); } @@ -283,6 +361,7 @@ void DBMaintenanceThread::run() m_log->debug("DBMaintenanceThread::run thread started."); Poco::DateTime now; + int i=0; do { @@ -293,11 +372,13 @@ void DBMaintenanceThread::run() Do10MinuteMaintenance(); m_last10minute=Poco::Timestamp(); } + /* if((m_last30minute+Poco::Timespan(0,0,30,0,0))<=now) { Do30MinuteMaintenance(); m_last30minute=Poco::Timestamp(); } + */ if((m_last1hour+Poco::Timespan(0,1,0,0,0))<=now) { Do1HourMaintenance(); @@ -314,7 +395,12 @@ void DBMaintenanceThread::run() m_last1day=Poco::Timestamp(); } - Poco::Thread::sleep(1000); + i=0; + while(i++<5 && !IsCancelled()) + { + Poco::Thread::sleep(1000); + } + }while(!IsCancelled()); m_log->debug("DBMaintenanceThread::run thread exiting.");