Fix #1583: flushing entries from the online profile cache would

make friend lists of other progiles incomplete. Also increased cache
size to 100.
This commit is contained in:
hiker 2014-10-07 16:52:18 +11:00
parent 6a47c157d2
commit ed7a114f5f
3 changed files with 49 additions and 4 deletions

View File

@ -125,6 +125,10 @@ public:
/** Returns true if the achievements for this profile have been fetched. */
bool hasFetchedAchievements() const { return m_has_fetched_achievements; }
// ------------------------------------------------------------------------
/** Unsets the flag that all friends of this profile are in cache. Used
* when a profile is pushed out of cache. */
void unsetHasFetchedFriends() { m_has_fetched_friends = false; }
// ------------------------------------------------------------------------
/** Returns true if the friend list for this profile has been fetched. */
bool hasFetchedFriends() const { return m_has_fetched_friends; }

View File

@ -38,7 +38,7 @@ ProfileManager* ProfileManager::m_profile_manager = NULL;
*/
ProfileManager::ProfileManager()
{
m_max_cache_size = 2;
m_max_cache_size = 100;
m_currently_visiting = NULL;
} // ProfileManager
@ -131,6 +131,7 @@ void ProfileManager::addDirectToCache(OnlineProfile* profile)
{
if (!iter->second->getCacheBit())
{
updateAllFriendFlags(iter->second);
delete iter->second;
iter = m_profiles_cache.erase(iter);
// Keep on deleting till enough space is available.
@ -163,6 +164,44 @@ bool ProfileManager::isInCache(const uint32_t id)
return false;
} // isInCache
// ------------------------------------------------------------------------
/** This function is called when the specified profile id is removed from
* cache. It will search all currently cached profiles that have the
* 'friends fetched' flag set, and reset that flag if the profile id is
* one of their friends. This fixes the problem that friend lists can
* get shortened if some of their friends are being pushed out of
* cache.
*/
void ProfileManager::updateFriendFlagsInCache(const ProfilesMap &cache,
uint32_t profile_id)
{
ProfilesMap::const_iterator i;
for(i=cache.begin(); i!=cache.end(); i++)
{
// Profile has no friends fetched, no need to test
if(!(*i).second->hasFetchedFriends()) continue;
const OnlineProfile::IDList &friend_list = (*i).second->getFriends();
OnlineProfile::IDList::const_iterator frnd;
frnd = std::find(friend_list.begin(), friend_list.end(), profile_id);
if(frnd!=friend_list.end())
(*i).second->unsetHasFetchedFriends();
}
} // updateFriendFlagsInCache
// ------------------------------------------------------------------------
/** This function is called when the specified profile is removed from
* cache. It searches through all caches for profiles X, that have the
* given profile as friend, and then reset the 'friends fetched' flag
* in profile X. Otherwise if a profile is pushed out of the cache,
* all friends of this profile in cache will have an incomplete list
* of friends.
*/
void ProfileManager::updateAllFriendFlags(const OnlineProfile *profile)
{
updateFriendFlagsInCache(m_profiles_persistent, profile->getID());
updateFriendFlagsInCache(m_profiles_cache, profile->getID());
} // updateAllFriendFlags
// ------------------------------------------------------------------------
/** This function updates the cache bits of all cached entries. It will
* set the cache bit of the given profile. Then, if the cachen is full

View File

@ -70,9 +70,11 @@ private:
* loaded, to make sure they can be all stored). */
unsigned int m_max_cache_size;
void updateCacheBits(OnlineProfile * profile);
void addDirectToCache(OnlineProfile * profile);
void updateCacheBits(OnlineProfile *profile);
void addDirectToCache(OnlineProfile *profile);
void updateFriendFlagsInCache(const ProfilesMap &cache,
uint32_t profile_id);
void updateAllFriendFlags(const OnlineProfile *profile);
public:
/** Create the singleton instance. */
static void create()