added notification for circle cache updates to avoid the need for an additional UI timer

This commit is contained in:
csoler 2020-02-11 16:37:53 +01:00
parent e4f243694b
commit f75d0add47
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
4 changed files with 42 additions and 8 deletions

View File

@ -187,6 +187,10 @@ enum class RsGxsCircleEventCode: uint8_t
/** mCircleId contains the circle id */
NEW_CIRCLE = 0x06,
/** no additional information. Simply means that the info previously from the cache has changed. */
CACHE_DATA_UPDATED = 0x07,
};
struct RsGxsCircleEvent: RsEvent

View File

@ -103,6 +103,7 @@
#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_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.
/********************************************************************************/
/******************* Startup / Tick ******************************************/
@ -117,11 +118,13 @@ p3GxsCircles::p3GxsCircles(
RsGxsCircles(static_cast<RsGxsIface&>(*this)), GxsTokenQueue(this),
RsTickEvent(), mIdentities(identities), mPgpUtils(pgpUtils),
mCircleMtx("p3GxsCircles"),
mCircleCache(DEFAULT_MEM_CACHE_SIZE, "GxsCircleCache" )
mCircleCache(DEFAULT_MEM_CACHE_SIZE, "GxsCircleCache" ),
mCacheUpdated(false)
{
// Kick off Cache Testing, + Others.
//RsTickEvent::schedule_in(CIRCLE_EVENT_CACHETEST, CACHETEST_PERIOD);
mLastCacheMembershipUpdateTS = 0 ;
mLastCacheUpdateEvent = 0;
RsTickEvent::schedule_now(CIRCLE_EVENT_LOADIDS);
@ -490,7 +493,21 @@ void p3GxsCircles::service_tick()
GxsTokenQueue::checkRequests(); // GxsTokenQueue handles all requests.
rstime_t now = time(NULL);
if(now > mLastCacheMembershipUpdateTS + GXS_CIRCLE_DELAY_TO_CHECK_MEMBERSHIP_UPDATE)
if(mCacheUpdated && now > mLastCacheUpdateEvent + GXS_CIRCLE_DELAY_TO_SEND_CACHE_UPDATED_EVENT)
{
if(rsEvents)
{
auto ev = std::make_shared<RsGxsCircleEvent>();
ev->mCircleEventType = RsGxsCircleEventCode::CACHE_DATA_UPDATED;
rsEvents->postEvent(ev);
}
mLastCacheUpdateEvent = now;
mCacheUpdated = false;
}
if(now > mLastCacheMembershipUpdateTS + GXS_CIRCLE_DELAY_TO_CHECK_MEMBERSHIP_UPDATE)
{
checkCircleCache();
mLastCacheMembershipUpdateTS = now ;
@ -552,6 +569,7 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
}
mCircleCache.erase(circle_id);
mCacheUpdated = true;
}
}
@ -577,6 +595,7 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
{
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
mCircleCache.erase(RsGxsCircleId(*git));
mCacheUpdated = true;
}
}
}
@ -646,6 +665,7 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
{
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
mCircleCache.erase(RsGxsCircleId(*git));
mCacheUpdated = true;
}
}
@ -700,7 +720,6 @@ bool p3GxsCircles::getCircleDetails(
}
}
return true;
}
}
@ -1462,6 +1481,7 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
RsTickEvent::schedule_in(CIRCLE_EVENT_RELOADIDS, GXSID_LOAD_CYCLE, id.toStdString());
}
mCacheUpdated = true;
}
return true;
@ -1498,6 +1518,8 @@ bool p3GxsCircles::locked_processLoadingCacheEntry(RsGxsCircleCache& cache)
if(mIdentities->haveKey(pit->first))
{
pit->second.subscription_flags |= GXS_EXTERNAL_CIRCLE_FLAGS_KEY_AVAILABLE;
mCacheUpdated = true;
#ifdef DEBUG_CIRCLES
std::cerr << " Key is now available!"<< std::endl;
#endif
@ -1573,8 +1595,8 @@ bool p3GxsCircles::locked_processLoadingCacheEntry(RsGxsCircleCache& cache)
// We can check for self inclusion in the circle right away, since own ids are always loaded.
// that allows to subscribe/unsubscribe uncomplete circles
locked_checkCircleCacheForAutoSubscribe(cache);
locked_checkCircleCacheForAutoSubscribe(cache);
locked_checkCircleCacheForMembershipUpdate(cache);
// always store in cache even if uncomplete. But do not remove the loading items so that they can be kept in loading state.
@ -1718,8 +1740,8 @@ bool p3GxsCircles::locked_checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cac
if(it2 != cache.mMembershipStatus.end())
{
in_admin_list = in_admin_list || bool(it2->second.subscription_flags & GXS_EXTERNAL_CIRCLE_FLAGS_IN_ADMIN_LIST) ;
member_request= member_request|| bool(it2->second.subscription_flags & GXS_EXTERNAL_CIRCLE_FLAGS_SUBSCRIBED) ;
in_admin_list = in_admin_list || bool(it2->second.subscription_flags & GXS_EXTERNAL_CIRCLE_FLAGS_IN_ADMIN_LIST) ;
member_request= member_request|| bool(it2->second.subscription_flags & GXS_EXTERNAL_CIRCLE_FLAGS_SUBSCRIBED) ;
}
}
@ -1748,6 +1770,8 @@ bool p3GxsCircles::locked_checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cac
RsGenExchange::setGroupStatusFlags(token2, RsGxsGroupId(cache.mCircleId), 0, GXS_SERV::GXS_GRP_STATUS_UNPROCESSED);
cache.mGroupStatus &= ~GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
mCacheUpdated = true;
return true;
}
@ -1771,6 +1795,7 @@ bool p3GxsCircles::locked_checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cac
cache.mGroupStatus &= ~GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
mCacheUpdated = true;
return true ;
}
}
@ -2427,6 +2452,7 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token)
else
std::cerr << " (EE) unknown subscription order type: " << item->subscription_type ;
mCacheUpdated = true;
#ifdef DEBUG_CIRCLES
std::cerr << " UPDATING" << std::endl;
#endif
@ -2441,7 +2467,8 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token)
}
data.mLastUpdatedMembershipTS = time(NULL) ;
}
mCacheUpdated = true;
}
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
uint32_t token2;

View File

@ -345,6 +345,8 @@ public:
uint32_t mDummyIdToken;
std::list<RsGxsId> mDummyPgpLinkedIds;
std::list<RsGxsId> mDummyOwnIds;
bool mCacheUpdated ;
rstime_t mLastCacheUpdateEvent;
RS_SET_CONTEXT_DEBUG_LEVEL(2)
};

View File

@ -429,6 +429,7 @@ void IdDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_LEAVE:
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_JOIN:
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REVOQUED:
case RsGxsCircleEventCode::CACHE_DATA_UPDATED:
updateCircles();
default: