diff options
author | James Cook <james@lindenlab.com> | 2010-04-20 17:05:49 -0700 |
---|---|---|
committer | James Cook <james@lindenlab.com> | 2010-04-20 17:05:49 -0700 |
commit | 022a598694cd37bebff3322054324c7d27afd5ff (patch) | |
tree | 81fbb61a86ee00c8b3287eaedd7da2af39da188f /indra | |
parent | 257c3ed2a3747256500f704f6e06e7631af3c08e (diff) |
Viewer caches avatar display names between sessions
Reviewed with Simon
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llcommon/llavatarname.cpp | 25 | ||||
-rw-r--r-- | indra/llcommon/llavatarname.h | 8 | ||||
-rw-r--r-- | indra/llmessage/llavatarnamecache.cpp | 34 | ||||
-rw-r--r-- | indra/newview/llappviewer.cpp | 18 |
4 files changed, 84 insertions, 1 deletions
diff --git a/indra/llcommon/llavatarname.cpp b/indra/llcommon/llavatarname.cpp index 5debf88818..62ba7cb112 100644 --- a/indra/llcommon/llavatarname.cpp +++ b/indra/llcommon/llavatarname.cpp @@ -35,6 +35,13 @@ #include "llavatarname.h" +// Store these in pre-built std::strings to avoid memory allocations in +// LLSD map lookups +static const std::string SL_ID("sl_id"); +static const std::string DISPLAY_NAME("display_name"); +static const std::string IS_DISPLAY_NAME_DEFAULT("is_display_name_default"); +static const std::string EXPIRES("expires"); + LLAvatarName::LLAvatarName() : mSLID(), mDisplayName(), @@ -50,3 +57,21 @@ bool LLAvatarName::operator<(const LLAvatarName& rhs) const else return mSLID < rhs.mSLID; } + +LLSD LLAvatarName::asLLSD() const +{ + LLSD sd; + sd[SL_ID] = mSLID; + sd[DISPLAY_NAME] = mDisplayName; + sd[IS_DISPLAY_NAME_DEFAULT] = mIsDisplayNameDefault; + sd[EXPIRES] = mExpires; + return sd; +} + +void LLAvatarName::fromLLSD(const LLSD& sd) +{ + mSLID = sd[SL_ID].asString(); + mDisplayName = sd[DISPLAY_NAME].asString(); + mIsDisplayNameDefault = sd[IS_DISPLAY_NAME_DEFAULT].asBoolean(); + mExpires = sd[EXPIRES].asReal(); +} diff --git a/indra/llcommon/llavatarname.h b/indra/llcommon/llavatarname.h index 72e2980b5c..11bd5f30b7 100644 --- a/indra/llcommon/llavatarname.h +++ b/indra/llcommon/llavatarname.h @@ -36,13 +36,19 @@ #include <string> +class LLSD; + class LL_COMMON_API LLAvatarName { public: LLAvatarName(); - + bool operator<(const LLAvatarName& rhs) const; + LLSD asLLSD() const; + + void fromLLSD(const LLSD& sd); + // "bobsmith123" or "james.linden", US-ASCII only std::string mSLID; diff --git a/indra/llmessage/llavatarnamecache.cpp b/indra/llmessage/llavatarnamecache.cpp index 69770c1f2a..d10958d09d 100644 --- a/indra/llmessage/llavatarnamecache.cpp +++ b/indra/llmessage/llavatarnamecache.cpp @@ -37,6 +37,7 @@ #include "llframetimer.h" #include "llhttpclient.h" #include "llsd.h" +#include "llsdserialize.h" #include <map> #include <set> @@ -243,10 +244,43 @@ void LLAvatarNameCache::cleanupClass() void LLAvatarNameCache::importFile(std::istream& istr) { + LLSD data; + S32 parse_count = LLSDSerialize::fromXMLDocument(data, istr); + if (parse_count < 1) return; + + // by convention LLSD storage is a map + // we only store one entry in the map + LLSD agents = data["agents"]; + + LLUUID agent_id; + LLAvatarName av_name; + LLSD::map_const_iterator it = agents.beginMap(); + for ( ; it != agents.endMap(); ++it) + { + agent_id.set(it->first); + av_name.fromLLSD( it->second ); + sCache[agent_id] = av_name; + } + // entries may have expired since we last ran the viewer, just + // clean them out now + eraseExpired(); + llinfos << "loaded " << sCache.size() << llendl; } void LLAvatarNameCache::exportFile(std::ostream& ostr) { + LLSD agents; + cache_t::const_iterator it = sCache.begin(); + for ( ; it != sCache.end(); ++it) + { + const LLUUID& agent_id = it->first; + const LLAvatarName& av_name = it->second; + // key must be a string + agents[agent_id.asString()] = av_name.asLLSD(); + } + LLSD data; + data["agents"] = agents; + LLSDSerialize::toPrettyXML(data, ostr); } void LLAvatarNameCache::setNameLookupURL(const std::string& name_lookup_url) diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 409146c4a3..ac9672858d 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -3333,6 +3333,15 @@ void LLAppViewer::saveFinalSnapshot() void LLAppViewer::loadNameCache() { + // display names cache + std::string filename = + gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "avatar_name_cache.xml"); + llifstream name_cache_stream(filename); + if(name_cache_stream.is_open()) + { + LLAvatarNameCache::importFile(name_cache_stream); + } + if (!gCacheName) return; std::string name_cache; @@ -3346,6 +3355,15 @@ void LLAppViewer::loadNameCache() void LLAppViewer::saveNameCache() { + // display names cache + std::string filename = + gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "avatar_name_cache.xml"); + llofstream name_cache_stream(filename); + if(name_cache_stream.is_open()) + { + LLAvatarNameCache::exportFile(name_cache_stream); + } + if (!gCacheName) return; std::string name_cache; |