mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Optimized the functions for the forum messages.
- used "const std::string&" for the parameters - used "std::map" for the read status - removed useless variables Added new define DEBUG_FORUMS in ForumsDialog.cpp. Added function to generate mass data for the forum messages. Fixed german language for the FriendsDialog. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4236 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9fb2ddfec0
commit
0dd77f6f27
8 changed files with 291 additions and 254 deletions
|
@ -402,7 +402,7 @@ void p3GroupDistrib::updateCacheDocument()
|
|||
pCacheId pCid;
|
||||
|
||||
int count = 0;
|
||||
int count2 = 0, count3 = 0;
|
||||
// int count2 = 0, count3 = 0;
|
||||
|
||||
for(; msgIt != mMsgHistPending.end(); msgIt++)
|
||||
{
|
||||
|
@ -2321,7 +2321,7 @@ void p3GroupDistrib::getPopularGroupList(uint32_t popMin, uint32_t popMax, std::
|
|||
|
||||
|
||||
/* get Msg Lists */
|
||||
bool p3GroupDistrib::getAllMsgList(std::string grpId, std::list<std::string> &msgIds)
|
||||
bool p3GroupDistrib::getAllMsgList(const std::string& grpId, std::list<std::string> &msgIds)
|
||||
{
|
||||
|
||||
RsStackMutex stack(distribMtx); /************* STACK MUTEX ************/
|
||||
|
@ -2346,7 +2346,7 @@ bool p3GroupDistrib::getAllMsgList(std::string grpId, std::list<std::string> &ms
|
|||
return true;
|
||||
}
|
||||
|
||||
bool p3GroupDistrib::getParentMsgList(std::string grpId, std::string pId,
|
||||
bool p3GroupDistrib::getParentMsgList(const std::string& grpId, const std::string& pId,
|
||||
std::list<std::string> &msgIds)
|
||||
{
|
||||
RsStackMutex stack(distribMtx); /************* STACK MUTEX ************/
|
||||
|
@ -2373,7 +2373,7 @@ bool p3GroupDistrib::getParentMsgList(std::string grpId, std::string pId,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool p3GroupDistrib::getTimePeriodMsgList(std::string grpId, uint32_t timeMin,
|
||||
bool p3GroupDistrib::getTimePeriodMsgList(const std::string& grpId, uint32_t timeMin,
|
||||
uint32_t timeMax, std::list<std::string> &msgIds)
|
||||
{
|
||||
RsStackMutex stack(distribMtx); /************* STACK MUTEX ************/
|
||||
|
@ -2397,7 +2397,7 @@ bool p3GroupDistrib::getTimePeriodMsgList(std::string grpId, uint32_t timeMin,
|
|||
}
|
||||
|
||||
|
||||
GroupInfo *p3GroupDistrib::locked_getGroupInfo(std::string grpId)
|
||||
GroupInfo *p3GroupDistrib::locked_getGroupInfo(const std::string& grpId)
|
||||
{
|
||||
/************* ALREADY LOCKED ************/
|
||||
std::map<std::string, GroupInfo>::iterator git;
|
||||
|
@ -2409,7 +2409,7 @@ GroupInfo *p3GroupDistrib::locked_getGroupInfo(std::string grpId)
|
|||
}
|
||||
|
||||
|
||||
RsDistribMsg *p3GroupDistrib::locked_getGroupMsg(std::string grpId, std::string msgId)
|
||||
RsDistribMsg *p3GroupDistrib::locked_getGroupMsg(const std::string& grpId, const std::string& msgId)
|
||||
{
|
||||
|
||||
/************* ALREADY LOCKED ************/
|
||||
|
@ -2765,7 +2765,6 @@ bool p3GroupDistrib::loadList(std::list<RsItem *>& load)
|
|||
RsSerialType* childSer = createSerialiser();
|
||||
grpCachePair gcPair;
|
||||
pCacheId cId;
|
||||
bool cached = false;
|
||||
for(lit = load.begin(); lit != load.end(); lit++)
|
||||
{
|
||||
/* decide what type it is */
|
||||
|
@ -2782,6 +2781,7 @@ bool p3GroupDistrib::loadList(std::list<RsItem *>& load)
|
|||
if(loadGroup(newGrp, false)){
|
||||
|
||||
#ifdef ENABLE_CACHE_OPT
|
||||
bool cached = false;
|
||||
RsStackMutex stack(distribMtx);
|
||||
|
||||
if(!locked_historyCached(newGrp->grpId, cached)){
|
||||
|
@ -5117,7 +5117,7 @@ bool p3GroupDistrib::locked_printDummyMsgs(GroupInfo &grp)
|
|||
/***** These Functions are used by the children classes to access the dummyData
|
||||
****/
|
||||
|
||||
bool p3GroupDistrib::getDummyParentMsgList(std::string grpId, std::string pId, std::list<std::string> &msgIds)
|
||||
bool p3GroupDistrib::getDummyParentMsgList(const std::string& grpId, const std::string& pId, std::list<std::string> &msgIds)
|
||||
{
|
||||
|
||||
#ifdef DISTRIB_DUMMYMSG_DEBUG
|
||||
|
@ -5159,9 +5159,8 @@ bool p3GroupDistrib::getDummyParentMsgList(std::string grpId, std::string pId, s
|
|||
}
|
||||
|
||||
|
||||
RsDistribDummyMsg *p3GroupDistrib::locked_getGroupDummyMsg(std::string grpId, std::string msgId)
|
||||
RsDistribDummyMsg *p3GroupDistrib::locked_getGroupDummyMsg(const std::string& grpId, const std::string& msgId)
|
||||
{
|
||||
|
||||
locked_processHistoryCached(grpId);
|
||||
#ifdef DISTRIB_DUMMYMSG_DEBUG
|
||||
std::cerr << "p3GroupDistrib::locked_getGroupDummyMsg(grpId:" << grpId << "," << msgId << ")";
|
||||
|
|
|
@ -545,14 +545,14 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
|
|||
|
||||
|
||||
/* get Msg Lists */
|
||||
bool getAllMsgList(std::string grpId, std::list<std::string> &msgIds);
|
||||
bool getParentMsgList(std::string grpId, std::string pId, std::list<std::string> &msgIds);
|
||||
bool getTimePeriodMsgList(std::string grpId, uint32_t timeMin,
|
||||
bool getAllMsgList(const std::string& grpId, std::list<std::string> &msgIds);
|
||||
bool getParentMsgList(const std::string& grpId, const std::string& pId, std::list<std::string> &msgIds);
|
||||
bool getTimePeriodMsgList(const std::string& grpId, uint32_t timeMin,
|
||||
uint32_t timeMax, std::list<std::string> &msgIds);
|
||||
|
||||
|
||||
GroupInfo *locked_getGroupInfo(std::string grpId);
|
||||
RsDistribMsg *locked_getGroupMsg(std::string grpId, std::string msgId);
|
||||
GroupInfo *locked_getGroupInfo(const std::string& grpId);
|
||||
RsDistribMsg *locked_getGroupMsg(const std::string& grpId, const std::string& msgId);
|
||||
|
||||
/*!
|
||||
* for retrieving the grpList for which public keys are available
|
||||
|
@ -834,8 +834,8 @@ bool locked_printAllDummyMsgs();
|
|||
bool locked_printDummyMsgs(GroupInfo &info);
|
||||
|
||||
/* access the dummy msgs */
|
||||
bool getDummyParentMsgList(std::string grpId, std::string pId, std::list<std::string> &msgIds);
|
||||
RsDistribDummyMsg *locked_getGroupDummyMsg(std::string grpId, std::string msgId);
|
||||
bool getDummyParentMsgList(const std::string& grpId, const std::string& pId, std::list<std::string> &msgIds);
|
||||
RsDistribDummyMsg *locked_getGroupDummyMsg(const std::string& grpId, const std::string& msgId);
|
||||
|
||||
|
||||
/* key cache functions - we use .... (not overloaded)
|
||||
|
|
|
@ -233,7 +233,7 @@ bool p3Forums::getForumThreadMsgList(const std::string &fId, const std::string &
|
|||
|
||||
getParentMsgList(fId, pId, msgIds);
|
||||
|
||||
std::list<std::string> msgDummyIds;
|
||||
std::list<std::string> msgDummyIds;
|
||||
getDummyParentMsgList(fId, pId, msgDummyIds);
|
||||
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
@ -357,6 +357,9 @@ bool p3Forums::ForumMessageSend(ForumMsgInfo &info)
|
|||
return false;
|
||||
}
|
||||
|
||||
// return id
|
||||
info.msgId = mId;
|
||||
|
||||
return setMessageStatus(info.forumId, mId, FORUM_MSG_STATUS_READ, FORUM_MSG_STATUS_MASK);
|
||||
}
|
||||
|
||||
|
@ -365,28 +368,18 @@ bool p3Forums::setMessageStatus(const std::string& fId,const std::string& mId,co
|
|||
{
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
||||
std::list<RsForumReadStatus *>::iterator lit = mReadStatus.begin();
|
||||
|
||||
for(; lit != mReadStatus.end(); lit++)
|
||||
{
|
||||
|
||||
if((*lit)->forumId == fId)
|
||||
{
|
||||
RsForumReadStatus* rsi = *lit;
|
||||
rsi->msgReadStatus[mId] &= ~statusMask;
|
||||
rsi->msgReadStatus[mId] |= (status & statusMask);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if forum id does not exist create one
|
||||
if(lit == mReadStatus.end())
|
||||
std::map<std::string, RsForumReadStatus*>::iterator mit = mReadStatus.find(fId);
|
||||
if (mit != mReadStatus.end())
|
||||
{
|
||||
RsForumReadStatus* rsi = mit->second;
|
||||
rsi->msgReadStatus[mId] &= ~statusMask;
|
||||
rsi->msgReadStatus[mId] |= (status & statusMask);
|
||||
} else {
|
||||
// if forum id does not exist create one
|
||||
RsForumReadStatus* rsi = new RsForumReadStatus();
|
||||
rsi->forumId = fId;
|
||||
rsi->msgReadStatus[mId] = status & statusMask;
|
||||
mReadStatus.push_back(rsi);
|
||||
mReadStatus[fId] = rsi;
|
||||
mSaveList.push_back(rsi);
|
||||
}
|
||||
|
||||
|
@ -400,33 +393,22 @@ bool p3Forums::setMessageStatus(const std::string& fId,const std::string& mId,co
|
|||
|
||||
bool p3Forums::getMessageStatus(const std::string& fId, const std::string& mId, uint32_t& status)
|
||||
{
|
||||
|
||||
status = 0;
|
||||
|
||||
RsStackMutex stack(distribMtx);
|
||||
|
||||
std::list<RsForumReadStatus *>::iterator lit = mReadStatus.begin();
|
||||
std::map<std::string, RsForumReadStatus*>::iterator fit = mReadStatus.find(fId);
|
||||
|
||||
for(; lit != mReadStatus.end(); lit++)
|
||||
{
|
||||
|
||||
if((*lit)->forumId == fId)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(lit == mReadStatus.end())
|
||||
if (fit == mReadStatus.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::map<std::string, uint32_t >::iterator mit = (*lit)->msgReadStatus.find(mId);
|
||||
std::map<std::string, uint32_t >::iterator rit = fit->second->msgReadStatus.find(mId);
|
||||
|
||||
if(mit != (*lit)->msgReadStatus.end())
|
||||
if(rit != fit->second->msgReadStatus.end())
|
||||
{
|
||||
status = mit->second;
|
||||
status = rit->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -569,28 +551,22 @@ bool p3Forums::getMessageCount(const std::string &fId, unsigned int &newCount, u
|
|||
if (grpFlags & (RS_DISTRIB_ADMIN | RS_DISTRIB_SUBSCRIBED)) {
|
||||
std::list<std::string> msgIds;
|
||||
if (getAllMsgList(fId, msgIds)) {
|
||||
std::list<std::string>::iterator mit;
|
||||
|
||||
RsStackMutex stack(distribMtx); /***** STACK LOCKED MUTEX *****/
|
||||
|
||||
std::list<RsForumReadStatus *>::iterator lit;
|
||||
for(lit = mReadStatus.begin(); lit != mReadStatus.end(); lit++) {
|
||||
if ((*lit)->forumId == fId) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lit == mReadStatus.end()) {
|
||||
std::map<std::string, RsForumReadStatus*>::iterator fit = mReadStatus.find(fId);
|
||||
if (fit == mReadStatus.end()) {
|
||||
// no status available -> all messages are new
|
||||
newCount += msgIds.size();
|
||||
unreadCount += msgIds.size();
|
||||
continue;
|
||||
}
|
||||
|
||||
std::list<std::string>::iterator mit;
|
||||
for (mit = msgIds.begin(); mit != msgIds.end(); mit++) {
|
||||
std::map<std::string, uint32_t >::iterator rit = (*lit)->msgReadStatus.find(*mit);
|
||||
std::map<std::string, uint32_t >::iterator rit = fit->second->msgReadStatus.find(*mit);
|
||||
|
||||
if (rit == (*lit)->msgReadStatus.end()) {
|
||||
if (rit == fit->second->msgReadStatus.end()) {
|
||||
// no status available -> message is new
|
||||
newCount++;
|
||||
unreadCount++;
|
||||
|
@ -799,7 +775,7 @@ bool p3Forums::childLoadList(std::list<RsItem* >& configSaves)
|
|||
{
|
||||
if(NULL != (drs = dynamic_cast<RsForumReadStatus* >(*it)))
|
||||
{
|
||||
mReadStatus.push_back(drs);
|
||||
mReadStatus[drs->forumId] = drs;
|
||||
mSaveList.push_back(drs);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -97,7 +97,7 @@ std::string createForumMsg(std::string fId, std::string pId,
|
|||
std::string mForumsDir;
|
||||
std::list<RsItem *> mSaveList; // store save data
|
||||
|
||||
std::list<RsForumReadStatus *> mReadStatus;
|
||||
std::map<std::string, RsForumReadStatus*> mReadStatus;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue