Merge pull request #1847 from csoler/v0.6-GxsDbFix

This branch aims at fixing the requests problems in RsGxsDataAccess
This commit is contained in:
csoler 2020-04-13 14:13:33 +02:00 committed by GitHub
commit b6c5e2f188
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 1059 additions and 774 deletions

View file

@ -62,13 +62,18 @@ void PostedDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
case RsPostedEventCode::NEW_MESSAGE:
case RsPostedEventCode::UPDATED_MESSAGE: // [[fallthrough]];
case RsPostedEventCode::READ_STATUS_CHANGED: // [[fallthrough]];
updateMessageSummaryList(e->mPostedGroupId);
updateGroupStatisticsReal(e->mPostedGroupId); // update the list immediately
break;
case RsPostedEventCode::NEW_POSTED_GROUP: // [[fallthrough]];
case RsPostedEventCode::SUBSCRIBE_STATUS_CHANGED: // [[fallthrough]];
updateDisplay(true);
break;
case RsPostedEventCode::STATISTICS_CHANGED:
updateGroupStatistics(e->mPostedGroupId);
break;
default: break;
}
}
@ -82,7 +87,7 @@ PostedDialog::~PostedDialog()
UserNotify *PostedDialog::createUserNotify(QObject *parent)
{
return new PostedUserNotify(rsPosted, parent);
return new PostedUserNotify(rsPosted, this, parent);
}
QString PostedDialog::getHelpString() const

View file

@ -22,8 +22,8 @@
#include "PostedUserNotify.h"
#include "gui/MainWindow.h"
PostedUserNotify::PostedUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) :
GxsUserNotify(ifaceImpl, parent)
PostedUserNotify::PostedUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent) :
GxsUserNotify(ifaceImpl, g, parent)
{
}
@ -34,10 +34,6 @@ bool PostedUserNotify::hasSetting(QString *name, QString *group)
return true;
}
bool PostedUserNotify::getServiceStatistics(GxsServiceStatistic& stat)
{
return rsPosted->getBoardsServiceStatistics(stat);
}
QIcon PostedUserNotify::getIcon()
{

View file

@ -28,10 +28,9 @@ class PostedUserNotify : public GxsUserNotify
Q_OBJECT
public:
PostedUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0);
PostedUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0);
virtual bool hasSetting(QString *name, QString *group);
virtual bool getServiceStatistics(GxsServiceStatistic& stat) override;
private:
virtual QIcon getIcon();

View file

@ -59,6 +59,8 @@
#define MAX_COMMENT_TITLE 32
static const uint32_t DELAY_BETWEEN_GROUP_STATISTICS_UPDATE = 120; // do not update group statistics more often than once every 2 mins
/*
* Transformation Notes:
* there are still a couple of things that the new groups differ from Old version.
@ -76,6 +78,9 @@ GxsGroupFrameDialog::GxsGroupFrameDialog(RsGxsIfaceHelper *ifaceImpl, QWidget *p
ui = new Ui::GxsGroupFrameDialog();
ui->setupUi(this);
mShouldUpdateMessageSummaryList = true;
mShouldUpdateGroupStatistics = false;
mLastGroupStatisticsUpdateTs=0;
mInitialized = false;
mDistSyncAllowed = allow_dist_sync;
mInFill = false;
@ -182,7 +187,43 @@ void GxsGroupFrameDialog::showEvent(QShowEvent *event)
initUi();
}
updateDisplay( mCachedGroupMetas.empty() );
uint32_t children = mYourGroups->childCount() + mSubscribedGroups->childCount() + mPopularGroups->childCount() + mOtherGroups->childCount();
bool empty = mCachedGroupMetas.empty() || children==0;
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();
}
rstime_t now = time(nullptr);
if(mShouldUpdateGroupStatistics && now > DELAY_BETWEEN_GROUP_STATISTICS_UPDATE + mLastGroupStatisticsUpdateTs)
{
// This mechanism allows to gather multiple updateGroupStatistics events at once and not send too many of them at the same time.
// it avoids re-loadign all the group everytime a friend sends new statistics.
for(auto& groupId: mGroupStatisticsToUpdate)
updateGroupStatisticsReal(groupId);
mShouldUpdateGroupStatistics = false;
mLastGroupStatisticsUpdateTs = time(nullptr);
mGroupStatisticsToUpdate.clear();
}
MainPage::paintEvent(pe);
}
void GxsGroupFrameDialog::processSettings(bool load)
@ -988,6 +1029,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;
@ -1072,6 +1125,12 @@ void GxsGroupFrameDialog::updateGroupSummary()
/*********************** **** **** **** ***********************/
void GxsGroupFrameDialog::updateGroupStatistics(const RsGxsGroupId &groupId)
{
mGroupStatisticsToUpdate.insert(groupId);
mShouldUpdateGroupStatistics = true;
}
void GxsGroupFrameDialog::updateGroupStatisticsReal(const RsGxsGroupId &groupId)
{
RsThread::async([this,groupId]()
{
@ -1083,7 +1142,7 @@ void GxsGroupFrameDialog::updateGroupStatistics(const RsGxsGroupId &groupId)
return;
}
RsQThreadUtils::postToObject( [this,stats]()
RsQThreadUtils::postToObject( [this,stats, groupId]()
{
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information
@ -1096,6 +1155,7 @@ void GxsGroupFrameDialog::updateGroupStatistics(const RsGxsGroupId &groupId)
return;
ui->groupTreeWidget->setUnreadCount(item, mCountChildMsgs ? (stats.mNumThreadMsgsUnread + stats.mNumChildMsgsUnread) : stats.mNumThreadMsgsUnread);
mCachedGroupStats[groupId] = stats;
getUserNotify()->updateIcon();
@ -1103,6 +1163,23 @@ void GxsGroupFrameDialog::updateGroupStatistics(const RsGxsGroupId &groupId)
});
}
void GxsGroupFrameDialog::getServiceStatistics(GxsServiceStatistic& stats) const
{
stats = GxsServiceStatistic(); // clears everything
for(auto it: mCachedGroupStats)
{
const GxsGroupStatistic& s(it.second);
stats.mNumMsgs += s.mNumMsgs;
stats.mNumGrps += 1;
stats.mSizeOfMsgs += s.mTotalSizeOfMsgs;
stats.mNumThreadMsgsNew += s.mNumThreadMsgsNew;
stats.mNumThreadMsgsUnread += s.mNumThreadMsgsUnread;
stats.mNumChildMsgsNew += s.mNumChildMsgsNew ;
stats.mNumChildMsgsUnread += s.mNumChildMsgsUnread ;
}
}
TurtleRequestId GxsGroupFrameDialog::distantSearch(const QString& search_string) // this should be overloaded in the child class
{

View file

@ -29,7 +29,6 @@
#include <inttypes.h>
#include "util/TokenQueue.h"
#include "GxsIdTreeWidgetItem.h"
#include "GxsGroupDialog.h"
@ -80,8 +79,11 @@ public:
virtual void getGroupList(std::map<RsGxsGroupId,RsGroupMetaData> &groups) ;
void getServiceStatistics(GxsServiceStatistic& stats) const ;
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; }
@ -102,6 +104,10 @@ protected:
virtual bool getGroupData(std::list<RsGxsGenericGroupData*>& groupInfo) =0;
virtual bool getGroupStatistics(const RsGxsGroupId& groupId,GxsGroupStatistic& stat) =0;
void updateGroupStatisticsReal(const RsGxsGroupId &groupId);
void updateMessageSummaryListReal(RsGxsGroupId groupId);
private slots:
void todo();
@ -173,20 +179,13 @@ private:
virtual uint32_t requestGroupSummaryType() { return GXS_REQUEST_TYPE_GROUP_META; } // request only meta data
void requestGroupStatistics(const RsGxsGroupId &groupId);
void loadGroupStatistics(const uint32_t &token);
// subscribe/unsubscribe ack.
// void acknowledgeSubscribeChange(const uint32_t &token);
GxsMessageFrameWidget *messageWidget(const RsGxsGroupId &groupId, bool ownTab);
GxsMessageFrameWidget *createMessageWidget(const RsGxsGroupId &groupId);
GxsCommentDialog *commentWidget(const RsGxsMessageId &msgId);
// void requestGroupSummary_CurrentGroup(const RsGxsGroupId &groupId);
// void loadGroupSummary_CurrentGroup(const uint32_t &token);
protected:
void updateSearchResults();
@ -209,12 +208,23 @@ private:
RsGxsGroupId mNavigatePendingGroupId;
RsGxsMessageId mNavigatePendingMsgId;
// Message summary list update
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;
// GroupStatistics update
bool mShouldUpdateGroupStatistics;
rstime_t mLastGroupStatisticsUpdateTs;
std::set<RsGxsGroupId> mGroupStatisticsToUpdate;
UIStateHelper *mStateHelper;
/** Qt Designer generated object */
Ui::GxsGroupFrameDialog *ui;
std::map<RsGxsGroupId,RsGroupMetaData> mCachedGroupMetas;
std::map<RsGxsGroupId,GxsGroupStatistic> mCachedGroupStats;
std::map<uint32_t,QTreeWidgetItem*> mSearchGroupsItems ;
std::map<uint32_t,std::set<RsGxsGroupId> > mKnownGroups;

View file

@ -26,7 +26,7 @@
#define TOKEN_TYPE_STATISTICS 1
GxsUserNotify::GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) : UserNotify(parent)
GxsUserNotify::GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g,QObject *parent) : UserNotify(parent), mGroupFrameDialog(g)
{
mNewThreadMessageCount = 0;
mNewChildMessageCount = 0;
@ -40,32 +40,17 @@ void GxsUserNotify::startUpdate()
mNewThreadMessageCount = 0;
mNewChildMessageCount = 0;
RsThread::async([this]()
{
// 1 - get message data from p3GxsForums
#ifdef DEBUG_FORUMS
std::cerr << "Retrieving post data for post " << mThreadId << std::endl;
#endif
GxsServiceStatistic stats;
mGroupFrameDialog->getServiceStatistics(stats);
GxsServiceStatistic stats;
if(!getServiceStatistics(stats))
return;
RsQThreadUtils::postToObject( [stats,this]()
{
/* Here it goes any code you want to be executed on the Qt Gui
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete */
mNewThreadMessageCount = stats.mNumThreadMsgsNew;
mNewChildMessageCount = stats.mNumChildMsgsNew;
mNewThreadMessageCount = stats.mNumThreadMsgsNew;
mNewChildMessageCount = stats.mNumChildMsgsNew;
update();
}, this );
});
update();
}

View file

@ -23,6 +23,7 @@
#include <QObject>
#include "gui/common/UserNotify.h"
#include "gui/gxs/GxsGroupFrameDialog.h"
#include "util/TokenQueue.h"
struct RsGxsIfaceHelper;
@ -33,12 +34,11 @@ class GxsUserNotify : public UserNotify
Q_OBJECT
public:
GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0);
GxsUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0);
virtual ~GxsUserNotify();
protected:
virtual void startUpdate();
virtual bool getServiceStatistics(GxsServiceStatistic& stat)=0;
private:
virtual unsigned int getNewCount() { return mCountChildMsgs ? (mNewThreadMessageCount + mNewChildMessageCount) : mNewThreadMessageCount; }
@ -48,6 +48,8 @@ protected:
private:
RsGxsUpdateBroadcastBase *mBase;
const GxsGroupFrameDialog *mGroupFrameDialog;
unsigned int mNewThreadMessageCount;
unsigned int mNewChildMessageCount;
};

View file

@ -64,10 +64,10 @@ 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::READ_STATUS_CHANGED:
updateMessageSummaryList(e->mChannelGroupId);
case RsChannelEventCode::NEW_MESSAGE: // [[fallthrough]];
case RsChannelEventCode::UPDATED_MESSAGE: // [[fallthrough]];
case RsChannelEventCode::READ_STATUS_CHANGED: // [[fallthrough]];
updateGroupStatisticsReal(e->mChannelGroupId); // update the list immediately
break;
case RsChannelEventCode::RECEIVED_DISTANT_SEARCH_RESULT:
@ -80,6 +80,10 @@ void GxsChannelDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> ev
updateDisplay(true);
break;
case RsChannelEventCode::STATISTICS_CHANGED:
updateGroupStatistics(e->mChannelGroupId);
break;
default:
break;
}
@ -109,7 +113,7 @@ QString GxsChannelDialog::getHelpString() const
UserNotify *GxsChannelDialog::createUserNotify(QObject *parent)
{
return new GxsChannelUserNotify(rsGxsChannels, parent);
return new GxsChannelUserNotify(rsGxsChannels,this, parent);
}
void GxsChannelDialog::shareOnChannel(const RsGxsGroupId& channel_id,const QList<RetroShareLink>& file_links)

View file

@ -22,8 +22,8 @@
#include "GxsChannelUserNotify.h"
#include "gui/MainWindow.h"
GxsChannelUserNotify::GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) :
GxsUserNotify(ifaceImpl, parent)
GxsChannelUserNotify::GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent) :
GxsUserNotify(ifaceImpl, g, parent)
{
}
@ -35,11 +35,6 @@ bool GxsChannelUserNotify::hasSetting(QString *name, QString *group)
return true;
}
bool GxsChannelUserNotify::getServiceStatistics(GxsServiceStatistic& stat)
{
return rsGxsChannels->getChannelServiceStatistics(stat);
}
QIcon GxsChannelUserNotify::getIcon()
{
return QIcon(":/icons/png/channel.png");

View file

@ -22,16 +22,16 @@
#define GXSCHANNELUSERNOTIFY_H
#include "gui/gxs/GxsUserNotify.h"
#include "gui/gxs/GxsGroupFrameDialog.h"
class GxsChannelUserNotify : public GxsUserNotify
{
Q_OBJECT
public:
GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0);
GxsChannelUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0);
virtual bool hasSetting(QString *name, QString *group);
virtual bool getServiceStatistics(GxsServiceStatistic& stat) override;
private:
virtual QIcon getIcon();

View file

@ -22,8 +22,8 @@
#include "GxsForumUserNotify.h"
#include "gui/MainWindow.h"
GxsForumUserNotify::GxsForumUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent) :
GxsUserNotify(ifaceImpl, parent)
GxsForumUserNotify::GxsForumUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent) :
GxsUserNotify(ifaceImpl, g, parent)
{
mCountChildMsgs = true;
}
@ -35,10 +35,6 @@ bool GxsForumUserNotify::hasSetting(QString *name, QString *group)
return true;
}
bool GxsForumUserNotify::getServiceStatistics(GxsServiceStatistic& stat)
{
return rsGxsForums->getForumServiceStatistics(stat);
}
QIcon GxsForumUserNotify::getIcon()
{

View file

@ -28,8 +28,7 @@ class GxsForumUserNotify : public GxsUserNotify
Q_OBJECT
public:
GxsForumUserNotify(RsGxsIfaceHelper *ifaceImpl, QObject *parent = 0);
virtual bool getServiceStatistics(GxsServiceStatistic& stat) override;
GxsForumUserNotify(RsGxsIfaceHelper *ifaceImpl, const GxsGroupFrameDialog *g, QObject *parent = 0);
virtual bool hasSetting(QString *name, QString *group);

View file

@ -62,13 +62,18 @@ void GxsForumsDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> eve
case RsForumEventCode::NEW_MESSAGE:
case RsForumEventCode::UPDATED_MESSAGE: // [[fallthrough]];
case RsForumEventCode::READ_STATUS_CHANGED:
updateMessageSummaryList(e->mForumGroupId);
updateGroupStatisticsReal(e->mForumGroupId); // update the list immediately
break;
case RsForumEventCode::NEW_FORUM: // [[fallthrough]];
case RsForumEventCode::SUBSCRIBE_STATUS_CHANGED:
updateDisplay(true);
break;
case RsForumEventCode::STATISTICS_CHANGED:
updateGroupStatistics(e->mForumGroupId); // update the list when redraw less often than once every 2 mins
break;
default:
break;
}
@ -133,7 +138,7 @@ void GxsForumsDialog::shareInMessage(const RsGxsGroupId& forum_id,const QList<Re
UserNotify *GxsForumsDialog::createUserNotify(QObject *parent)
{
return new GxsForumUserNotify(rsGxsForums, parent);
return new GxsForumUserNotify(rsGxsForums,this, parent);
}
QString GxsForumsDialog::text(TextType type)