fixed notifications on circle not working due to cache reload failure. That circle cache code needs a real cleanup

This commit is contained in:
csoler 2020-05-04 20:54:08 +02:00
parent ce6abe5d66
commit 65fa29e789
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 303 additions and 268 deletions

View File

@ -103,7 +103,7 @@
#define MIN_CIRCLE_LOAD_GAP 5 #define MIN_CIRCLE_LOAD_GAP 5
#define GXS_CIRCLE_DELAY_TO_FORCE_MEMBERSHIP_UPDATE 60 // re-check every 1 mins. Normally this shouldn't be necessary since notifications inform abotu new messages. #define GXS_CIRCLE_DELAY_TO_FORCE_MEMBERSHIP_UPDATE 60 // re-check every 1 mins. Normally this shouldn't be necessary since notifications inform abotu new messages.
#define GXS_CIRCLE_DELAY_TO_CHECK_MEMBERSHIP_UPDATE 60 // re-check every 1 mins. Normally this shouldn't be necessary since notifications inform abotu new messages. #define GXS_CIRCLE_DELAY_TO_CHECK_MEMBERSHIP_UPDATE 60 // re-check every 1 mins. Normally this shouldn't be necessary since notifications inform abotu new messages.
#define GXS_CIRCLE_DELAY_TO_SEND_CACHE_UPDATED_EVENT 10 // do not send cache update events more often than every 10 secs. #define GXS_CIRCLE_DELAY_TO_SEND_CACHE_UPDATED_EVENT 2 // do not send cache update events more often than every 2 secs.
/********************************************************************************/ /********************************************************************************/
/******************* Startup / Tick ******************************************/ /******************* Startup / Tick ******************************************/
@ -532,6 +532,7 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
#endif #endif
p3Notify *notify = RsServer::notify(); p3Notify *notify = RsServer::notify();
std::set<RsGxsCircleId> circles_to_reload;
for(auto it = changes.begin(); it != changes.end(); ++it) for(auto it = changes.begin(); it != changes.end(); ++it)
{ {
@ -576,6 +577,7 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
} }
mCircleCache.erase(circle_id); mCircleCache.erase(circle_id);
circles_to_reload.insert(circle_id);
mCacheUpdated = true; mCacheUpdated = true;
} }
@ -608,6 +610,7 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
mCircleCache.erase(RsGxsCircleId(*git)); mCircleCache.erase(RsGxsCircleId(*git));
mCacheUpdated = true; mCacheUpdated = true;
circles_to_reload.insert(RsGxsCircleId(*git));
} }
} }
} }
@ -686,6 +689,7 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
mCircleCache.erase(RsGxsCircleId(*git)); mCircleCache.erase(RsGxsCircleId(*git));
mCacheUpdated = true; mCacheUpdated = true;
circles_to_reload.insert(RsGxsCircleId(*git));
} }
} }
@ -693,6 +697,9 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
delete c; delete c;
} }
for(auto& circle_id:circles_to_reload)
force_cache_reload(circle_id);
} }
/********************************************************************************/ /********************************************************************************/

View File

@ -294,16 +294,34 @@ void NewsFeed::handleChannelEvent(std::shared_ptr<const RsEvent> event)
void NewsFeed::handleCircleEvent(std::shared_ptr<const RsEvent> event) void NewsFeed::handleCircleEvent(std::shared_ptr<const RsEvent> event)
{ {
// Gives the backend a few secs to load the cache data while not blocking the UI. This is not so nice, but there's no proper
// other way to do that.
RsThread::async( [event,this]()
{
const RsGxsCircleEvent *pe = dynamic_cast<const RsGxsCircleEvent*>(event.get()); const RsGxsCircleEvent *pe = dynamic_cast<const RsGxsCircleEvent*>(event.get());
if(!pe) if(!pe)
return; return;
RsGxsCircleDetails details;
if(pe->mCircleId.isNull()) // probably an item for cache update if(pe->mCircleId.isNull()) // probably an item for cache update
return ; return ;
if(!rsGxsCircles->getCircleDetails(pe->mCircleId,details)) RsGxsCircleDetails details;
bool loaded = false;
for(int i=0;i<5 && !loaded;++i)
if(rsGxsCircles->getCircleDetails(pe->mCircleId,details))
{
std::cerr << "Cache item loaded for circle " << pe->mCircleId << std::endl;
loaded = true;
}
else
{
std::cerr << "Cache item for circle " << pe->mCircleId << " not loaded. Waiting " << i << "s" << std::endl;
rstime::rs_usleep(1000*1000);
}
if(!loaded)
{ {
std::cerr << "(EE) Cannot get information about circle " << pe->mCircleId << ". Not in cache?" << std::endl; std::cerr << "(EE) Cannot get information about circle " << pe->mCircleId << ". Not in cache?" << std::endl;
return; return;
@ -346,6 +364,10 @@ void NewsFeed::handleCircleEvent(std::shared_ptr<const RsEvent> event)
// Note: In this case you're never an admin of the circle, since these notification // Note: In this case you're never an admin of the circle, since these notification
// would be a direct consequence of your own actions. // would be a direct consequence of your own actions.
RsQThreadUtils::postToObject( [event,details,this]()
{
const RsGxsCircleEvent *pe = static_cast<const RsGxsCircleEvent*>(event.get());
switch(pe->mCircleEventType) switch(pe->mCircleEventType)
{ {
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REQUEST: case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REQUEST:
@ -385,6 +407,7 @@ void NewsFeed::handleCircleEvent(std::shared_ptr<const RsEvent> event)
default: break; default: break;
} }
}, this ); }); // damn!
} }
void NewsFeed::handleConnectionEvent(std::shared_ptr<const RsEvent> event) void NewsFeed::handleConnectionEvent(std::shared_ptr<const RsEvent> event)

View File

@ -86,13 +86,13 @@ void GxsCircleItem::setup()
RsGxsCircleDetails circleDetails; RsGxsCircleDetails circleDetails;
if (rsGxsCircles->getCircleDetails(mCircleId, circleDetails)) if (rsGxsCircles->getCircleDetails(mCircleId, circleDetails))
{ {
ui->nameLabel->setText(QString::fromUtf8(circleDetails.mCircleName.c_str()) + " (ID: " + QString::fromStdString(circleDetails.mCircleId.toStdString()) + ")");
// from here we can figure out if we already have requested membership or not // from here we can figure out if we already have requested membership or not
if (mType == RS_FEED_ITEM_CIRCLE_MEMB_REQ) if (mType == RS_FEED_ITEM_CIRCLE_MEMB_REQ)
{ {
ui->titleLabel->setText(tr("You received a membership request a circle you're administrating:")); ui->titleLabel->setText(tr("You received a membership request a circle you're administrating:"));
ui->nameLabel->setText(QString::fromUtf8(circleDetails.mCircleName.c_str()));
ui->gxsIdLabel->setText(idName);
ui->iconLabel->setPixmap(pixmap); ui->iconLabel->setPixmap(pixmap);
ui->gxsIdLabel->setId(mGxsId); ui->gxsIdLabel->setId(mGxsId);
@ -102,8 +102,6 @@ void GxsCircleItem::setup()
else if (mType == RS_FEED_ITEM_CIRCLE_INVITE_REC) else if (mType == RS_FEED_ITEM_CIRCLE_INVITE_REC)
{ {
ui->titleLabel->setText(tr("You received an invitation for this circle:")); ui->titleLabel->setText(tr("You received an invitation for this circle:"));
ui->nameLabel->setText(QString::fromUtf8(circleDetails.mCircleName.c_str()));
ui->gxsIdLabel->setText(idName);
ui->iconLabel->setPixmap(pixmap); ui->iconLabel->setPixmap(pixmap);
ui->gxsIdLabel->setId(mGxsId); ui->gxsIdLabel->setId(mGxsId);
@ -114,8 +112,6 @@ void GxsCircleItem::setup()
else if (mType == RS_FEED_ITEM_CIRCLE_MEMB_LEAVE) else if (mType == RS_FEED_ITEM_CIRCLE_MEMB_LEAVE)
{ {
ui->titleLabel->setText(idName + tr(" has left this circle.")); ui->titleLabel->setText(idName + tr(" has left this circle."));
ui->nameLabel->setText(QString::fromUtf8(circleDetails.mCircleName.c_str()));
ui->gxsIdLabel->setText(idName);
ui->iconLabel->setPixmap(pixmap); ui->iconLabel->setPixmap(pixmap);
ui->gxsIdLabel->setId(mGxsId); ui->gxsIdLabel->setId(mGxsId);
@ -125,8 +121,6 @@ void GxsCircleItem::setup()
else if (mType == RS_FEED_ITEM_CIRCLE_MEMB_JOIN) else if (mType == RS_FEED_ITEM_CIRCLE_MEMB_JOIN)
{ {
ui->titleLabel->setText(idName + tr(" which you invited, has join this circle you're administrating.")); ui->titleLabel->setText(idName + tr(" which you invited, has join this circle you're administrating."));
ui->nameLabel->setText(QString::fromUtf8(circleDetails.mCircleName.c_str()));
ui->gxsIdLabel->setText(idName);
ui->iconLabel->setPixmap(pixmap); ui->iconLabel->setPixmap(pixmap);
ui->gxsIdLabel->setId(mGxsId); ui->gxsIdLabel->setId(mGxsId);
@ -137,8 +131,6 @@ void GxsCircleItem::setup()
{ {
ui->titleLabel->setText(tr("Your identity %1 has been revoked from this circle.").arg(idName)); ui->titleLabel->setText(tr("Your identity %1 has been revoked from this circle.").arg(idName));
ui->nameLabel->setText(QString::fromUtf8(circleDetails.mCircleName.c_str()));
ui->gxsIdLabel->setText(idName);
ui->iconLabel->setPixmap(pixmap); ui->iconLabel->setPixmap(pixmap);
ui->gxsIdLabel->setId(mGxsId); ui->gxsIdLabel->setId(mGxsId);
@ -149,8 +141,6 @@ void GxsCircleItem::setup()
{ {
ui->titleLabel->setText(tr("Your identity %1 as been accepted in this circle.").arg(idName)); ui->titleLabel->setText(tr("Your identity %1 as been accepted in this circle.").arg(idName));
ui->nameLabel->setText(QString::fromUtf8(circleDetails.mCircleName.c_str()));
ui->gxsIdLabel->setText(idName);
ui->iconLabel->setPixmap(pixmap); ui->iconLabel->setPixmap(pixmap);
ui->gxsIdLabel->setId(mGxsId); ui->gxsIdLabel->setId(mGxsId);

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>618</width> <width>618</width>
<height>104</height> <height>172</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="GxsCircleItemGLayout"> <layout class="QGridLayout" name="GxsCircleItemGLayout">
@ -104,8 +104,8 @@
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Sunken</enum> <enum>QFrame::Sunken</enum>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item row="0" column="0" rowspan="3"> <item>
<widget class="QLabel" name="logoLabel"> <widget class="QLabel" name="logoLabel">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
@ -130,12 +130,68 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1" colspan="5"> <item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="titleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<italic>true</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true">Circle msg</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="nameHLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Circle name:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="nameLabel">
<property name="text">
<string notr="true">name</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="nameHSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLabel" name="forLabel"> <widget class="QLabel" name="forLabel">
<property name="text"> <property name="text">
<string>for identity</string> <string>Identity:</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -180,7 +236,9 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="2" column="1"> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="acceptButton"> <widget class="QPushButton" name="acceptButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -200,7 +258,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="2"> <item>
<widget class="QPushButton" name="revokeButton"> <widget class="QPushButton" name="revokeButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -220,7 +278,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="3"> <item>
<widget class="QPushButton" name="expandButton"> <widget class="QPushButton" name="expandButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -240,7 +298,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="4"> <item>
<spacer name="tollbarHSpacer"> <spacer name="tollbarHSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -256,7 +314,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="5"> <item>
<widget class="QPushButton" name="clearButton"> <widget class="QPushButton" name="clearButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -276,50 +334,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" colspan="5"> </layout>
<layout class="QHBoxLayout" name="nameHLayout">
<item>
<widget class="QLabel" name="titleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<italic>true</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true">Circle</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="nameLabel">
<property name="text">
<string notr="true">name</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="nameHSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</item> </item>
@ -336,8 +351,8 @@
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../images.qrc"/>
<include location="../icons.qrc"/> <include location="../icons.qrc"/>
<include location="../images.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>