X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ffreenet%2Fmessagelistinserter.cpp;h=6fda2443dbbc419a1982285ded48b7e32834d4a0;hb=5c0453c8697cfaa843dd7f799e5404733ee56e13;hp=57d40f9930b3073bd514129455a126cccc3b31cd;hpb=6b896a9e1dc143bba86795be1e9336549db9b85f;p=fms.git diff --git a/src/freenet/messagelistinserter.cpp b/src/freenet/messagelistinserter.cpp index 57d40f9..6fda244 100644 --- a/src/freenet/messagelistinserter.cpp +++ b/src/freenet/messagelistinserter.cpp @@ -11,7 +11,7 @@ MessageListInserter::MessageListInserter() Initialize(); } -MessageListInserter::MessageListInserter(FCPv2 *fcp):IIndexInserter(fcp) +MessageListInserter::MessageListInserter(FCPv2 *fcp):IIndexInserter(fcp) { Initialize(); } @@ -21,6 +21,7 @@ void MessageListInserter::CheckForNeededInsert() // only do 1 insert at a time if(m_inserting.size()==0) { + std::string sql; DateTime now; DateTime previous; @@ -29,10 +30,15 @@ void MessageListInserter::CheckForNeededInsert() previous.Add(0,0,0,-m_daysbackward); - // query for identities that have messages in the past X days and we haven't inserted lists for in the past hour - SQLite3DB::Statement st=m_db->Prepare("SELECT tblLocalIdentity.LocalIdentityID FROM tblLocalIdentity INNER JOIN tblMessageInserts ON tblLocalIdentity.LocalIdentityID=tblMessageInserts.LocalIdentityID WHERE tblMessageInserts.Day>=? AND (tblLocalIdentity.LastInsertedMessageList<=? OR tblLocalIdentity.LastInsertedMessageList IS NULL OR tblLocalIdentity.LastInsertedMessageList='');"); + // query for identities that have messages in the past X days and (we haven't inserted lists for in the past 30 minutes OR identity has a record in tmpMessageListInsert) + 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+=";"; + + SQLite3DB::Statement st=m_db->Prepare(sql); st.Bind(0,previous.Format("%Y-%m-%d")); - st.Bind(1,(now-(1.0/24.0)).Format("%Y-%m-%d %H:%M:%S")); + st.Bind(1,(now-(1.0/48.0)).Format("%Y-%m-%d %H:%M:%S")); st.Step(); if(st.RowReturned()) @@ -93,8 +99,15 @@ const bool MessageListInserter::HandlePutSuccessful(FCPMessage &message) st.Bind(1,localidentityid); st.Step(); + // delete any record from tmpMessageListInsert + st=m_db->Prepare("DELETE FROM tmpMessageListInsert WHERE LocalIdentityID=?;"); + st.Bind(0,localidentityid); + st.Step(); + RemoveFromInsertList(localidentityid); + m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"MessageListInserter::HandlePutSuccessful successfully inserted MessageList."); + return true; } @@ -104,7 +117,7 @@ void MessageListInserter::Initialize() m_fcpuniquename="MessageListInserter"; m_daysbackward=0; - Option::instance()->Get("MessageListDaysBackward",tempval); + Option::Instance()->Get("MessageListDaysBackward",tempval); StringFunctions::Convert(tempval,m_daysbackward); } @@ -152,6 +165,40 @@ void 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 100;"); + 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; + int index; + std::string publickey; + std::vector boardlist; + int messageid; + + st.ResultText(0,day); + st.ResultInt(1,index); + st.ResultText(2,publickey); + st.ResultInt(3,messageid); + + st2.Bind(0,messageid); + st2.Step(); + while(st2.RowReturned()) + { + std::string boardname=""; + st2.ResultText(0,boardname); + StringFunctions::LowerCase(boardname,boardname); + boardlist.push_back(boardname); + st2.Step(); + } + st2.Reset(); + + mlxml.AddExternalMessage(publickey,day,index,boardlist); + + st.Step(); + } + // get last inserted messagelist index for this day index=0; st=m_db->Prepare("SELECT MAX(InsertIndex) FROM tblMessageListInserts WHERE LocalIdentityID=? AND Day=?;");