checked in first bits of code for cache service data optimisation,

distrib can build grps xml document
added pugixml src code into utilities

pls see design document:
http://retroshare.sourceforge.net/wiki/index.php/Documentation:design_services_histories

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4076 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2011-03-04 22:16:25 +00:00
parent 976aadc1b3
commit ec0ce30103
8 changed files with 10906 additions and 2 deletions

View file

@ -155,6 +155,15 @@ int p3GroupDistrib::tick()
receivePubKeys();
}
// update cache table every minute
bool updateCacheDoc = false;
{
updateCacheDoc = (now > (time_t) (mLastCacheDocUpdate + 60.));
}
if(false)
updateCacheDocument(mCacheDoc);
return 0;
}
@ -221,6 +230,66 @@ bool p3GroupDistrib::loadLocalCache(const CacheData &data)
}
void p3GroupDistrib::updateCacheDocument(pugi::xml_document& cacheDoc)
{
#ifdef DISTRIB_DEBUG
std::cerr << "p3GroupDistrib::updateCacheDocument() "
<< std::endl;
#endif
/*
* find group ids put down in mGroupCacheIds to be set into
* the cache document then their subsequent messages
*/
std::map<std::string, std::string>::iterator cit =
mGroupCacheIds.begin(), mit = mMsgCacheIds.begin();
std::map<std::string, GroupInfo>::iterator git;
std::map<std::string, RsDistribMsg *>::iterator msgIt;
for(; cit != mGroupCacheIds.end(); cit++){
// add the group at depth on
git = mGroups.find(cit->first);
if(git != mGroups.end()){
// add another group node
cacheDoc.append_child("group");
// then add title
cacheDoc.last_child().append_child("title").append_child(
pugi::node_pcdata).set_value(git->second.grpId.c_str());
// then add the id
cacheDoc.last_child().append_child("id").append_child(
pugi::node_pcdata).set_value(cit->second
.c_str());
}
}
#ifdef DISTRIB_DEBUG
std::cerr << "p3GroupDistrib::updateCacheDocument() "
<< "\nFinished Building xml doc, \n saving to file"
<< std::endl;
#endif
cacheDoc.save_file("distrib_group.xml");
mLastCacheDocUpdate = time(NULL);
// essentially build by gathering all your group
// now do the same with messages which may have arrived for a group
}
/* Handle the Cache Pending Setup */
CacheDataPending::CacheDataPending(const CacheData &data, bool local, bool historical)
:mData(data), mLocal(local), mHistorical(historical)
@ -376,6 +445,7 @@ void p3GroupDistrib::loadFileGroups(const std::string &filename, const std::stri
newKey = dynamic_cast<RsDistribGrpKey *>(item);
if ((newGrp = dynamic_cast<RsDistribGrp *>(item)))
{
loadGroup(newGrp, historical);
}
else if ((newKey = dynamic_cast<RsDistribGrpKey *>(item)))

View file

@ -314,6 +314,10 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
void HistoricalCachesDone(); // called when Stored Caches have been added to Pending List.
protected:
void updateCacheDocument(pugi::xml_document& cacheDoc);
private:
/* these lists are filled by the overloaded fns... then cleared by the thread */
@ -755,6 +759,14 @@ RsDistribDummyMsg *locked_getGroupDummyMsg(std::string grpId, std::string msgId)
std::map<std::string, std::list<std::string> > mPendingPubKeyRecipients; /// peers to receive publics key for a given grp
std::set<std::string> mPubKeyAvailableGrpId; // groups id for which public keys are available
time_t mLastKeyPublishTime, mLastRecvdKeyTime;
////////////// cache optimisation ////////////////
/// look table to calculate data location
std::map<std::string, std::string> mGroupCacheIds, mMsgCacheIds;
std::map<std::string, std::string> mGroupMessageIds;
time_t mLastCacheDocUpdate;
pugi::xml_document mCacheDoc;
};