X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ffreenet%2Fmessagelistinserter.cpp;h=eb943ffb0ce47b6b582d52572171412d05b5fde0;hb=ed0732b2550c23c05fc9faf925620e87ee6dee12;hp=56e70136d824bda8392fb92aeb7d22714d0edb36;hpb=59a5414ec47a2932a7802fcd1d98c4d80166564f;p=fms.git diff --git a/src/freenet/messagelistinserter.cpp b/src/freenet/messagelistinserter.cpp index 56e7013..eb943ff 100644 --- a/src/freenet/messagelistinserter.cpp +++ b/src/freenet/messagelistinserter.cpp @@ -22,6 +22,14 @@ MessageListInserter::MessageListInserter(SQLite3DB::DB *db, FCPv2::Connection *f void MessageListInserter::CheckForNeededInsert() { + + // more than 10 minutes trying to insert - restart + if(m_inserting.size()>0 && (m_laststartedinsert+Poco::Timespan(0,0,10,0,0)<=Poco::DateTime())) + { + m_log->error("MessageListInserter::CheckForNeededInsert more than 10 minutes have passed without success/failure. Clearing inserts."); + m_inserting.clear(); + } + // only do 1 insert at a time if(m_inserting.size()==0) { @@ -42,7 +50,8 @@ void MessageListInserter::CheckForNeededInsert() sql="SELECT tblLocalIdentity.LocalIdentityID "; sql+="FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID "; sql+="WHERE tblMessageInserts.Day>=? AND ((tblLocalIdentity.LastInsertedMessageList<=? OR tblLocalIdentity.LastInsertedMessageList IS NULL OR tblLocalIdentity.LastInsertedMessageList='') OR tblLocalIdentity.LocalIdentityID IN (SELECT LocalIdentityID FROM tmpMessageListInsert)) "; - sql+="GROUP BY tblLocalIdentity.LocalIdentityID;"; + sql+="GROUP BY tblLocalIdentity.LocalIdentityID "; + sql+="ORDER BY tblLocalIdentity.LastInsertedMessageList;"; SQLite3DB::Statement st=m_db->Prepare(sql); st.Bind(0,Poco::DateTimeFormatter::format(previous,"%Y-%m-%d")); @@ -204,9 +213,10 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) st.Finalize(); - st=m_db->Prepare("SELECT MessageDate, MessageIndex, PublicKey, MessageID FROM tblMessage INNER JOIN tblIdentity ON tblMessage.IdentityID=tblIdentity.IdentityID WHERE MessageIndex IS NOT NULL ORDER BY MessageDate DESC, MessageTime DESC LIMIT 200;"); + st=m_db->Prepare("SELECT MessageDate, MessageIndex, PublicKey, MessageID FROM tblMessage INNER JOIN tblIdentity ON tblMessage.IdentityID=tblIdentity.IdentityID WHERE MessageIndex IS NOT NULL ORDER BY MessageDate DESC, MessageTime DESC LIMIT 175;"); SQLite3DB::Statement st2=m_db->Prepare("SELECT BoardName FROM tblBoard INNER JOIN tblMessageBoard ON tblBoard.BoardID=tblMessageBoard.BoardID WHERE tblMessageBoard.MessageID=?;"); st.Step(); + while(st.RowReturned()) { std::string day; @@ -280,10 +290,19 @@ const bool MessageListInserter::StartInsert(const long &localidentityid) m_inserting.push_back(localidentityid); m_lastinsertedxml[localidentityid]=xmlstr; + m_laststartedinsert=Poco::DateTime(); + return true; } else { + + // xml was the same one that we inserted 30 minutes ago, reset date so we don't continue checking every minute + st=m_db->Prepare("UPDATE tblLocalIdentity SET LastInsertedMessageList=? WHERE LocalIdentityID=?;"); + st.Bind(0,Poco::DateTimeFormatter::format(Poco::DateTime(),"%Y-%m-%d %H:%M:%S")); + st.Bind(1,localidentityid); + st.Step(); + return false; }