Hide debug messages from p3historymgr

This commit is contained in:
AsamK 2015-09-09 16:18:47 +02:00
parent 75d462e818
commit 0e2417dfd7

View File

@ -34,6 +34,10 @@
#include "rsserver/p3face.h" #include "rsserver/p3face.h"
#include "util/rsstring.h" #include "util/rsstring.h"
/****
* #define HISTMGR_DEBUG 1
***/
// clean too old messages every 5 minutes // clean too old messages every 5 minutes
// //
#define MSG_HISTORY_CLEANING_PERIOD 300 #define MSG_HISTORY_CLEANING_PERIOD 300
@ -171,7 +175,9 @@ void p3HistoryMgr::cleanOldMessages()
{ {
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
#ifdef HISTMGR_DEBUG
std::cerr << "****** cleaning old messages." << std::endl; std::cerr << "****** cleaning old messages." << std::endl;
#endif
time_t now = time(NULL) ; time_t now = time(NULL) ;
bool changed = false ; bool changed = false ;
@ -185,7 +191,9 @@ void p3HistoryMgr::cleanOldMessages()
std::map<uint32_t, RsHistoryMsgItem*>::iterator lit2 = lit ; std::map<uint32_t, RsHistoryMsgItem*>::iterator lit2 = lit ;
++lit2 ; ++lit2 ;
#ifdef HISTMGR_DEBUG
std::cerr << " removing msg id " << lit->first << ", for peer id " << mit->first << std::endl; std::cerr << " removing msg id " << lit->first << ", for peer id " << mit->first << std::endl;
#endif
delete lit->second ; delete lit->second ;
mit->second.erase(lit) ; mit->second.erase(lit) ;
@ -201,7 +209,9 @@ void p3HistoryMgr::cleanOldMessages()
{ {
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit2 = mit ; std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit2 = mit ;
++mit2 ; ++mit2 ;
std::cerr << " removing peer id " << mit->first << ", since it has no messages" << std::endl; #ifdef HISTMGR_DEBUG
std::cerr << " removing peer id " << mit->first << ", since it has no messages" << std::endl;
#endif
mMessages.erase(mit) ; mMessages.erase(mit) ;
mit = mit2 ; mit = mit2 ;
@ -306,7 +316,9 @@ bool p3HistoryMgr::loadList(std::list<RsItem*>& load)
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(msgItem->chatPeerId); std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(msgItem->chatPeerId);
msgItem->msgId = nextMsgId++; msgItem->msgId = nextMsgId++;
#ifdef HISTMGR_DEBUG
std::cerr << "Loading msg history item: peer id=" << msgItem->chatPeerId << "), msg id =" << msgItem->msgId << std::endl; std::cerr << "Loading msg history item: peer id=" << msgItem->chatPeerId << "), msg id =" << msgItem->msgId << std::endl;
#endif
if (mit != mMessages.end()) { if (mit != mMessages.end()) {
mit->second.insert(std::make_pair(msgItem->msgId, msgItem)); mit->second.insert(std::make_pair(msgItem->msgId, msgItem));
@ -344,7 +356,9 @@ bool p3HistoryMgr::loadList(std::list<RsItem*>& load)
if (sscanf(kit->value.c_str(), "%d", &val) == 1) if (sscanf(kit->value.c_str(), "%d", &val) == 1)
mMaxStorageDurationSeconds = val ; mMaxStorageDurationSeconds = val ;
#ifdef HISTMGR_DEBUG
std::cerr << "Loaded max storage time for history = " << val << " seconds" << std::endl; std::cerr << "Loaded max storage time for history = " << val << " seconds" << std::endl;
#endif
continue; continue;
} }
@ -446,7 +460,9 @@ bool p3HistoryMgr::getMessages(const ChatId &chatId, std::list<HistoryMsg> &msgs
if(!chatIdToVirtualPeerId(chatId, chatPeerId)) if(!chatIdToVirtualPeerId(chatId, chatPeerId))
return false; return false;
#ifdef HISTMGR_DEBUG
std::cerr << "Getting history for virtual peer " << chatPeerId << std::endl; std::cerr << "Getting history for virtual peer " << chatPeerId << std::endl;
#endif
uint32_t foundCount = 0; uint32_t foundCount = 0;
@ -467,7 +483,9 @@ bool p3HistoryMgr::getMessages(const ChatId &chatId, std::list<HistoryMsg> &msgs
} }
} }
} }
#ifdef HISTMGR_DEBUG
std::cerr << msgs.size() << " messages added." << std::endl; std::cerr << msgs.size() << " messages added." << std::endl;
#endif
return true; return true;
} }
@ -497,7 +515,9 @@ void p3HistoryMgr::clear(const ChatId &chatId)
if(!chatIdToVirtualPeerId(chatId, chatPeerId)) if(!chatIdToVirtualPeerId(chatId, chatPeerId))
return; return;
#ifdef HISTMGR_DEBUG
std::cerr << "********** p3History::clear()called for virtual peer id " << chatPeerId << std::endl; std::cerr << "********** p3History::clear()called for virtual peer id " << chatPeerId << std::endl;
#endif
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId); std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
if (mit == mMessages.end()) { if (mit == mMessages.end()) {
@ -523,7 +543,9 @@ void p3HistoryMgr::removeMessages(const std::list<uint32_t> &msgIds)
std::list<uint32_t> removedIds; std::list<uint32_t> removedIds;
std::list<uint32_t>::iterator iit; std::list<uint32_t>::iterator iit;
#ifdef HISTMGR_DEBUG
std::cerr << "********** p3History::removeMessages called()" << std::endl; std::cerr << "********** p3History::removeMessages called()" << std::endl;
#endif
{ {
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
@ -536,7 +558,9 @@ void p3HistoryMgr::removeMessages(const std::list<uint32_t> &msgIds)
std::map<uint32_t, RsHistoryMsgItem*>::iterator lit = mit->second.find(*iit); std::map<uint32_t, RsHistoryMsgItem*>::iterator lit = mit->second.find(*iit);
if (lit != mit->second.end()) if (lit != mit->second.end())
{ {
#ifdef HISTMGR_DEBUG
std::cerr << "**** Removing " << mit->first << " msg id = " << lit->first << std::endl; std::cerr << "**** Removing " << mit->first << " msg id = " << lit->first << std::endl;
#endif
delete(lit->second); delete(lit->second);
mit->second.erase(lit); mit->second.erase(lit);