mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 16:39:29 -05:00
added notification for circle cache updates to avoid the need for an additional UI timer
This commit is contained in:
parent
e4f243694b
commit
f75d0add47
@ -187,6 +187,10 @@ enum class RsGxsCircleEventCode: uint8_t
|
|||||||
|
|
||||||
/** mCircleId contains the circle id */
|
/** mCircleId contains the circle id */
|
||||||
NEW_CIRCLE = 0x06,
|
NEW_CIRCLE = 0x06,
|
||||||
|
|
||||||
|
/** no additional information. Simply means that the info previously from the cache has changed. */
|
||||||
|
CACHE_DATA_UPDATED = 0x07,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RsGxsCircleEvent: RsEvent
|
struct RsGxsCircleEvent: RsEvent
|
||||||
|
@ -103,6 +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.
|
||||||
|
|
||||||
/********************************************************************************/
|
/********************************************************************************/
|
||||||
/******************* Startup / Tick ******************************************/
|
/******************* Startup / Tick ******************************************/
|
||||||
@ -117,11 +118,13 @@ p3GxsCircles::p3GxsCircles(
|
|||||||
RsGxsCircles(static_cast<RsGxsIface&>(*this)), GxsTokenQueue(this),
|
RsGxsCircles(static_cast<RsGxsIface&>(*this)), GxsTokenQueue(this),
|
||||||
RsTickEvent(), mIdentities(identities), mPgpUtils(pgpUtils),
|
RsTickEvent(), mIdentities(identities), mPgpUtils(pgpUtils),
|
||||||
mCircleMtx("p3GxsCircles"),
|
mCircleMtx("p3GxsCircles"),
|
||||||
mCircleCache(DEFAULT_MEM_CACHE_SIZE, "GxsCircleCache" )
|
mCircleCache(DEFAULT_MEM_CACHE_SIZE, "GxsCircleCache" ),
|
||||||
|
mCacheUpdated(false)
|
||||||
{
|
{
|
||||||
// Kick off Cache Testing, + Others.
|
// Kick off Cache Testing, + Others.
|
||||||
//RsTickEvent::schedule_in(CIRCLE_EVENT_CACHETEST, CACHETEST_PERIOD);
|
//RsTickEvent::schedule_in(CIRCLE_EVENT_CACHETEST, CACHETEST_PERIOD);
|
||||||
mLastCacheMembershipUpdateTS = 0 ;
|
mLastCacheMembershipUpdateTS = 0 ;
|
||||||
|
mLastCacheUpdateEvent = 0;
|
||||||
|
|
||||||
RsTickEvent::schedule_now(CIRCLE_EVENT_LOADIDS);
|
RsTickEvent::schedule_now(CIRCLE_EVENT_LOADIDS);
|
||||||
|
|
||||||
@ -490,6 +493,20 @@ void p3GxsCircles::service_tick()
|
|||||||
GxsTokenQueue::checkRequests(); // GxsTokenQueue handles all requests.
|
GxsTokenQueue::checkRequests(); // GxsTokenQueue handles all requests.
|
||||||
|
|
||||||
rstime_t now = time(NULL);
|
rstime_t now = time(NULL);
|
||||||
|
|
||||||
|
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)
|
if(now > mLastCacheMembershipUpdateTS + GXS_CIRCLE_DELAY_TO_CHECK_MEMBERSHIP_UPDATE)
|
||||||
{
|
{
|
||||||
checkCircleCache();
|
checkCircleCache();
|
||||||
@ -552,6 +569,7 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mCircleCache.erase(circle_id);
|
mCircleCache.erase(circle_id);
|
||||||
|
mCacheUpdated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,6 +595,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -646,6 +665,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -700,7 +720,6 @@ bool p3GxsCircles::getCircleDetails(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
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());
|
RsTickEvent::schedule_in(CIRCLE_EVENT_RELOADIDS, GXSID_LOAD_CYCLE, id.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mCacheUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -1498,6 +1518,8 @@ bool p3GxsCircles::locked_processLoadingCacheEntry(RsGxsCircleCache& cache)
|
|||||||
if(mIdentities->haveKey(pit->first))
|
if(mIdentities->haveKey(pit->first))
|
||||||
{
|
{
|
||||||
pit->second.subscription_flags |= GXS_EXTERNAL_CIRCLE_FLAGS_KEY_AVAILABLE;
|
pit->second.subscription_flags |= GXS_EXTERNAL_CIRCLE_FLAGS_KEY_AVAILABLE;
|
||||||
|
|
||||||
|
mCacheUpdated = true;
|
||||||
#ifdef DEBUG_CIRCLES
|
#ifdef DEBUG_CIRCLES
|
||||||
std::cerr << " Key is now available!"<< std::endl;
|
std::cerr << " Key is now available!"<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -1749,6 +1771,8 @@ bool p3GxsCircles::locked_checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cac
|
|||||||
|
|
||||||
cache.mGroupStatus &= ~GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
|
cache.mGroupStatus &= ~GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
|
||||||
|
|
||||||
|
mCacheUpdated = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1771,6 +1795,7 @@ bool p3GxsCircles::locked_checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cac
|
|||||||
|
|
||||||
cache.mGroupStatus &= ~GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
|
cache.mGroupStatus &= ~GXS_SERV::GXS_GRP_STATUS_UNPROCESSED;
|
||||||
|
|
||||||
|
mCacheUpdated = true;
|
||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2427,6 +2452,7 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token)
|
|||||||
else
|
else
|
||||||
std::cerr << " (EE) unknown subscription order type: " << item->subscription_type ;
|
std::cerr << " (EE) unknown subscription order type: " << item->subscription_type ;
|
||||||
|
|
||||||
|
mCacheUpdated = true;
|
||||||
#ifdef DEBUG_CIRCLES
|
#ifdef DEBUG_CIRCLES
|
||||||
std::cerr << " UPDATING" << std::endl;
|
std::cerr << " UPDATING" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
@ -2441,6 +2467,7 @@ bool p3GxsCircles::processMembershipRequests(uint32_t token)
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.mLastUpdatedMembershipTS = time(NULL) ;
|
data.mLastUpdatedMembershipTS = time(NULL) ;
|
||||||
|
mCacheUpdated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
@ -345,6 +345,8 @@ public:
|
|||||||
uint32_t mDummyIdToken;
|
uint32_t mDummyIdToken;
|
||||||
std::list<RsGxsId> mDummyPgpLinkedIds;
|
std::list<RsGxsId> mDummyPgpLinkedIds;
|
||||||
std::list<RsGxsId> mDummyOwnIds;
|
std::list<RsGxsId> mDummyOwnIds;
|
||||||
|
bool mCacheUpdated ;
|
||||||
|
rstime_t mLastCacheUpdateEvent;
|
||||||
|
|
||||||
RS_SET_CONTEXT_DEBUG_LEVEL(2)
|
RS_SET_CONTEXT_DEBUG_LEVEL(2)
|
||||||
};
|
};
|
||||||
|
@ -429,6 +429,7 @@ void IdDialog::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
|
|||||||
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_LEAVE:
|
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_LEAVE:
|
||||||
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_JOIN:
|
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_JOIN:
|
||||||
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REVOQUED:
|
case RsGxsCircleEventCode::CIRCLE_MEMBERSHIP_REVOQUED:
|
||||||
|
case RsGxsCircleEventCode::CACHE_DATA_UPDATED:
|
||||||
|
|
||||||
updateCircles();
|
updateCircles();
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user