{\r
std::string dbres=TestDBIntegrity(m_db);\r
m_log->trace("DBMaintenanceThread::Do10MinuteMaintenance() middle TestDBIntegrity returned "+dbres);\r
+ if(dbres!="ok")\r
+ {\r
+ m_db->Execute("REINDEX;");\r
+ dbres=TestDBIntegrity(m_db);\r
+ m_log->trace("DBMaintenanceThread::Do10MinuteMaintenenace() middle after reindex returned "+dbres);\r
+ }\r
}\r
\r
// now rebuild threads where the message has been deleted\r
st.Step();\r
}\r
\r
+ st.Finalize();\r
+ upd.Finalize();\r
+\r
// insert all identities not in trust list already\r
m_db->Execute("INSERT INTO tblIdentityTrust(LocalIdentityID,IdentityID) SELECT LocalIdentityID,IdentityID FROM tblLocalIdentity,tblIdentity WHERE LocalIdentityID || '_' || IdentityID NOT IN (SELECT LocalIdentityID || '_' || IdentityID FROM tblIdentityTrust);");\r
\r
st.Step();\r
}\r
\r
+ st.Finalize();\r
+ st2.Finalize();\r
+ upd.Finalize();\r
+\r
m_db->Execute("COMMIT;");\r
\r
m_log->debug("PeriodicDBMaintenance::Do6HourMaintenance");\r
// try to re-attach messages from identities that were previously deleted, but have been since re-added\r
// first get the names from messages that have a NULL IdentityID\r
SQLite3DB::Statement st=m_db->Prepare("SELECT FromName FROM tblMessage WHERE IdentityID IS NULL GROUP BY FromName;");\r
+ SQLite3DB::Statement findst=m_db->Prepare("SELECT IdentityID,PublicKey FROM tblIdentity WHERE Name=?;");\r
st.Step();\r
while(st.RowReturned())\r
{\r
}\r
\r
// find identities with this name\r
- SQLite3DB::Statement st2=m_db->Prepare("SELECT IdentityID,PublicKey FROM tblIdentity WHERE Name=?;");\r
- st2.Bind(0,namepart);\r
- st2.Step();\r
- while(st2.RowReturned())\r
+ findst.Bind(0,namepart);\r
+ findst.Step();\r
+ while(findst.RowReturned())\r
{\r
publickey="";\r
identityid=0;\r
- st2.ResultText(1,publickey);\r
+ findst.ResultText(1,publickey);\r
// check if public key matches 2nd part\r
if(parts.size()>1 && publickey.find(parts[1])==4)\r
{\r
// we have the identity - so update the messages table with the identityid\r
- st2.ResultInt(0,identityid);\r
+ findst.ResultInt(0,identityid);\r
\r
SQLite3DB::Statement st3=m_db->Prepare("UPDATE tblMessage SET IdentityID=? WHERE FromName=? AND IdentityID IS NULL;");\r
st3.Bind(0,identityid);\r
st3.Bind(1,name);\r
st3.Step();\r
}\r
- st2.Step();\r
+ findst.Step();\r
}\r
+ findst.Reset();\r
\r
st.Step();\r
}\r
m_db->Execute("DELETE FROM tblIdentityTrust WHERE LocalIdentityID NOT IN (SELECT LocalIdentityID FROM tblLocalIdentity);");\r
m_db->Execute("DELETE FROM tblIdentityTrust WHERE IdentityID NOT IN (SELECT IdentityID FROM tblIdentity);");\r
\r
+\r
+ // reduce failure count for each identity\r
+ m_db->Execute("UPDATE tblIdentity SET FailureCount=0 WHERE FailureCount<(SELECT OptionValue FROM tblOption WHERE Option='FailureCountReduction');");\r
+ m_db->Execute("UPDATE tblIdentity SET FailureCount=FailureCount-(SELECT OptionValue FROM tblOption WHERE OptionName='FailureCountReduction') WHERE FailureCount>=(SELECT OptionValue FROM tblOption WHERE Option='FailureCountReduction');");\r
+\r
+ st.Finalize();\r
+ findst.Finalize();\r
+\r
m_db->Execute("COMMIT;");\r
\r
m_log->debug("PeriodicDBMaintenance::Do1DayMaintenance");\r