fixed up the update of message count using a flag to only update when necessary, which limits drastically the calls to getGroupsStatistics()

This commit is contained in:
csoler 2020-04-06 21:55:07 +02:00
parent 65af73f8eb
commit 5c71a46c52
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 42 additions and 16 deletions

View File

@ -335,14 +335,6 @@ RsTokenService::GxsRequestStatus RsGxsDataAccess::requestStatus(uint32_t token)
uint32_t anstype;
rstime_t ts;
// {
// RS_STACK_MUTEX(mDataMutex);
//
// // first check public tokens
// if(mPublicToken.find(token) != mPublicToken.end())
// return mPublicToken[token];
// }
if (!checkRequestStatus(token, status, reqtype, anstype, ts))
return RsTokenService::FAILED;
@ -724,9 +716,6 @@ GxsRequest* RsGxsDataAccess::locked_retrieveCompetedRequest(const uint32_t& toke
void RsGxsDataAccess::processRequests()
{
// process requests
#ifdef DATA_DEBUG
RsDbg() << "processing requests" << std::endl;
#endif
while (!mRequestQueue.empty())
{
@ -762,6 +751,7 @@ void RsGxsDataAccess::processRequests()
case PENDING:
req = mRequestQueue.begin()->second;
req->status = PARTIAL;
mRequestQueue.erase(mRequestQueue.begin()); // remove it right away from the waiting queue.
break;
}
@ -1486,7 +1476,7 @@ bool RsGxsDataAccess::getGroupStatistic(GroupStatisticRequest *req)
GxsMsgMetaResult metaResult;
mDataStore->retrieveGxsMsgMetaData(metaReq, metaResult);
std::vector<RsGxsMsgMetaData*>& msgMetaV = metaResult[req->mGrpId];
const std::vector<RsGxsMsgMetaData*>& msgMetaV = metaResult[req->mGrpId];
req->mGroupStatistic.mGrpId = req->mGrpId;
req->mGroupStatistic.mNumMsgs = msgMetaV.size();

View File

@ -182,7 +182,26 @@ void GxsGroupFrameDialog::showEvent(QShowEvent *event)
initUi();
}
updateDisplay( mCachedGroupMetas.empty() );
bool empty = mCachedGroupMetas.empty();
updateDisplay( empty );
}
void GxsGroupFrameDialog::paintEvent(QPaintEvent *pe)
{
if(mShouldUpdateMessageSummaryList)
{
if(!mGroupIdsSummaryToUpdate.empty())
for(auto& group_id: mGroupIdsSummaryToUpdate)
updateMessageSummaryListReal(group_id);
else
updateMessageSummaryListReal(RsGxsGroupId());
mShouldUpdateMessageSummaryList = false;
mGroupIdsSummaryToUpdate.clear();
}
MainPage::paintEvent(pe);
}
void GxsGroupFrameDialog::processSettings(bool load)
@ -988,6 +1007,18 @@ void GxsGroupFrameDialog::insertGroupsData(const std::list<RsGxsGenericGroupData
}
void GxsGroupFrameDialog::updateMessageSummaryList(RsGxsGroupId groupId)
{
// groupId.isNull() means that we need to update all groups so we clear up the list of groups to update.
if(!groupId.isNull())
mGroupIdsSummaryToUpdate.insert(groupId);
else
mGroupIdsSummaryToUpdate.clear();
mShouldUpdateMessageSummaryList = true;
}
void GxsGroupFrameDialog::updateMessageSummaryListReal(RsGxsGroupId groupId)
{
if (!mInitialized) {
return;

View File

@ -81,7 +81,8 @@ public:
virtual void getGroupList(std::map<RsGxsGroupId,RsGroupMetaData> &groups) ;
protected:
virtual void showEvent(QShowEvent *event);
virtual void showEvent(QShowEvent *event) override;
virtual void paintEvent(QPaintEvent *pe) override;
virtual void updateDisplay(bool complete);
const RsGxsGroupId &groupId() { return mGroupId; }
@ -159,6 +160,7 @@ private:
void initUi();
void updateMessageSummaryListReal(RsGxsGroupId groupId);
void openGroupInNewTab(const RsGxsGroupId &groupId);
void groupSubscribe(bool subscribe);
@ -209,6 +211,9 @@ private:
RsGxsGroupId mNavigatePendingGroupId;
RsGxsMessageId mNavigatePendingMsgId;
bool mShouldUpdateMessageSummaryList ; // whether we should update the counting for groups. This takes some CPU so we only do it when needed.
std::set<RsGxsGroupId> mGroupIdsSummaryToUpdate;
UIStateHelper *mStateHelper;
/** Qt Designer generated object */

View File

@ -64,8 +64,8 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
switch(e->mChannelEventCode)
{
case RsChannelEventCode::NEW_MESSAGE:
case RsChannelEventCode::UPDATED_MESSAGE: // [[fallthrough]];
case RsChannelEventCode::NEW_MESSAGE: // [[fallthrough]];
case RsChannelEventCode::UPDATED_MESSAGE:
case RsChannelEventCode::READ_STATUS_CHANGED:
updateMessageSummaryList(e->mChannelGroupId);
break;