created a connexion between token and meta data of created posts and grps

This commit is contained in:
csoler 2018-10-16 22:40:27 +02:00
parent 2bb24075c4
commit 9b4c48c540
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 135 additions and 76 deletions

View File

@ -1189,6 +1189,26 @@ bool RsGenExchange::getMsgRelatedList(const uint32_t &token, MsgRelatedIdResult
{ {
return mDataAccess->getMsgRelatedList(token, msgIds); return mDataAccess->getMsgRelatedList(token, msgIds);
} }
bool RsGenExchange::getPublishedMsgMeta(const uint32_t& token,RsMsgMetaData& meta)
{
auto it = mPublishedMsgs.find(token);
if(it == mPublishedMsgs.end())
return false ;
meta = it->second;
return true;
}
bool RsGenExchange::getPublishedGroupMeta(const uint32_t& token,RsGroupMetaData& meta)
{
auto it = mPublishedGrps.find(token);
if(it == mPublishedGrps.end())
return false ;
meta = it->second;
return true;
}
bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo) bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list<RsGroupMetaData> &groupInfo)
{ {
@ -2164,7 +2184,7 @@ void RsGenExchange::publishMsgs()
#endif #endif
RsGxsMsgItem* msgItem = mit->second; RsGxsMsgItem* msgItem = mit->second;
const uint32_t& token = mit->first; uint32_t token = mit->first;
uint32_t size = mSerialiser->size(msgItem); uint32_t size = mSerialiser->size(msgItem);
char* mData = new char[size]; char* mData = new char[size];
@ -2279,6 +2299,9 @@ void RsGenExchange::publishMsgs()
computeHash(msg->msg, msg->metaData->mHash); computeHash(msg->msg, msg->metaData->mHash);
mDataAccess->addMsgData(msg); mDataAccess->addMsgData(msg);
mPublishedMsgs[token] = *msg->metaData;
delete msg ; delete msg ;
msgChangeMap[grpId].insert(msgId); msgChangeMap[grpId].insert(msgId);
@ -2669,6 +2692,7 @@ void RsGenExchange::publishGrps()
#warning csoler: TODO: grp->meta should be renamed grp->public_meta ! #warning csoler: TODO: grp->meta should be renamed grp->public_meta !
grp->meta.setBinData(metaData, mdSize); grp->meta.setBinData(metaData, mdSize);
} }
mPublishedGrps[ggps.mToken] = *grp->metaData ; // save the connexion between the token and the created metadata, without private keys
// Place back private keys for publisher and database storage // Place back private keys for publisher and database storage
grp->metaData->keys.private_keys = fullKeySet.private_keys; grp->metaData->keys.private_keys = fullKeySet.private_keys;

View File

@ -242,6 +242,21 @@ public:
*/ */
bool getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMap& msgMeta); bool getMsgRelatedMeta(const uint32_t &token, GxsMsgRelatedMetaMap& msgMeta);
/*!
* Retrieves the meta data of a newly created group. The meta is kept in cache for the current session.
* \param token token that was used to create the group
* \param meta meta data for this group
* \return false if the group is not yet created.
*/
bool getPublishedGroupMeta(const uint32_t& token,RsGroupMetaData& meta);
/*!
* Retrieves the meta data of a newly created post. The meta is kept in cache for the current session.
* \param token token that was used to create the post
* \param meta meta data for this post
* \return false if the group is not yet created.
*/
bool getPublishedMsgMeta(const uint32_t& token,RsMsgMetaData& meta);
/*! /*!
* Gxs services should call this for automatic handling of * Gxs services should call this for automatic handling of
@ -883,6 +898,9 @@ private:
std::vector<GxsGrpPendingSign> mGrpsToPublish; std::vector<GxsGrpPendingSign> mGrpsToPublish;
typedef std::vector<GxsGrpPendingSign> NxsGrpSignPendVect; typedef std::vector<GxsGrpPendingSign> NxsGrpSignPendVect;
std::map<uint32_t,RsGxsGrpMetaData> mPublishedGrps ; // keeps track of which group was created using which token
std::map<uint32_t,RsGxsMsgMetaData> mPublishedMsgs ; // keeps track of which message was created using which token
std::map<uint32_t, RsGxsMsgItem*> mMsgsToPublish; std::map<uint32_t, RsGxsMsgItem*> mMsgsToPublish;
std::map<uint32_t, RsGxsGrpMsgIdPair > mMsgNotify; std::map<uint32_t, RsGxsGrpMsgIdPair > mMsgNotify;

View File

@ -1046,48 +1046,54 @@ bool p3GxsChannels::createChannel(RsGxsChannelGroup& channel)
{ {
uint32_t token; uint32_t token;
time_t beginCreation = time(nullptr); time_t beginCreation = time(nullptr);
if( !createGroup(token, channel) if( !createGroup(token, channel) || waitToken(token) != RsTokenService::COMPLETE )
|| waitToken(token) != RsTokenService::COMPLETE )
return false; return false;
time_t endCreation = time(nullptr);
std::list<RsGroupMetaData> channels; if(RsGenExchange::getPublishedGroupMeta(token,channel.mMeta))
if(!getChannelsSummaries(channels)) return false;
/* This is ugly but after digging and doing many tries of doing it the right
* way ending always into too big refactor chain reaction, I think this is
* not that bad, moreover seems the last created group tend to end up near
* the beginning of the list so it is fast founding it.
* The shortcoming of this is that if groups with same data are created in
* a burst (more then once in a second) is that the id of another similar
* group can be returned, but this is a pointy case.
* Order of conditions in the `if` matter for performances */
bool found = false;
for(const RsGroupMetaData& chan : channels)
{ {
if( IS_GROUP_ADMIN(chan.mSubscribeFlags)
&& IS_GROUP_SUBSCRIBED(chan.mSubscribeFlags)
&& chan.mPublishTs >= beginCreation
&& chan.mPublishTs <= endCreation
&& chan.mGroupFlags == channel.mMeta.mGroupFlags
&& chan.mSignFlags == channel.mMeta.mSignFlags
&& chan.mCircleType == channel.mMeta.mCircleType
&& chan.mAuthorId == channel.mMeta.mAuthorId
&& chan.mCircleId == channel.mMeta.mCircleId
&& chan.mServiceString == channel.mMeta.mServiceString
&& chan.mGroupName == channel.mMeta.mGroupName )
{
channel.mMeta = chan;
found = true;
break;
}
}
#ifdef RS_DEEP_SEARCH #ifdef RS_DEEP_SEARCH
if(found) DeepSearch::indexChannelGroup(channel); if(found) DeepSearch::indexChannelGroup(channel);
#endif // RS_DEEP_SEARCH #endif // RS_DEEP_SEARCH
return found; return true;
}
else
return false;
// time_t endCreation = time(nullptr);
//
//
// std::list<RsGroupMetaData> channels;
// if(!getChannelsSummaries(channels)) return false;
//
// /* This is ugly but after digging and doing many tries of doing it the right
// * way ending always into too big refactor chain reaction, I think this is
// * not that bad, moreover seems the last created group tend to end up near
// * the beginning of the list so it is fast founding it.
// * The shortcoming of this is that if groups with same data are created in
// * a burst (more then once in a second) is that the id of another similar
// * group can be returned, but this is a pointy case.
// * Order of conditions in the `if` matter for performances */
// bool found = false;
// for(const RsGroupMetaData& chan : channels)
// {
// if( IS_GROUP_ADMIN(chan.mSubscribeFlags)
// && IS_GROUP_SUBSCRIBED(chan.mSubscribeFlags)
// && chan.mPublishTs >= beginCreation
// && chan.mPublishTs <= endCreation
// && chan.mGroupFlags == channel.mMeta.mGroupFlags
// && chan.mSignFlags == channel.mMeta.mSignFlags
// && chan.mCircleType == channel.mMeta.mCircleType
// && chan.mAuthorId == channel.mMeta.mAuthorId
// && chan.mCircleId == channel.mMeta.mCircleId
// && chan.mServiceString == channel.mMeta.mServiceString
// && chan.mGroupName == channel.mMeta.mGroupName )
// {
// channel.mMeta = chan;
// found = true;
// break;
// }
// }
} }
bool p3GxsChannels::createPost(RsGxsChannelPost& post) bool p3GxsChannels::createPost(RsGxsChannelPost& post)
@ -1098,49 +1104,60 @@ bool p3GxsChannels::createPost(RsGxsChannelPost& post)
|| waitToken(token) != RsTokenService::COMPLETE ) return false; || waitToken(token) != RsTokenService::COMPLETE ) return false;
time_t endCreation = time(nullptr); time_t endCreation = time(nullptr);
std::list<RsGxsGroupId> chanIds; chanIds.push_back(post.mMeta.mGroupId); if(RsGenExchange::getPublishedMsgMeta(token,post.mMeta))
std::vector<RsGxsChannelPost> posts;
std::vector<RsGxsComment> comments;
if(!getChannelsContent(chanIds, posts, comments)) return false;
/* This is ugly but after digging and doing many tries of doing it the right
* way ending always into too big refactor chain reaction, I think this is
* not that bad.
* The shortcoming of this is that if posts with same data are created in
* a burst (more then once in a second) is that the id of another similar
* post could be returned, but this is a pointy case.
* Order of conditions in the `if` matter for performances */
bool found = false;
for(const RsGxsChannelPost& itPost : posts)
{ {
std::cout << __PRETTY_FUNCTION__ << " " << beginCreation << " "
<< itPost.mMeta.mPublishTs << " " << endCreation << " "
<< itPost.mMeta.mMsgId << std::endl;
if( itPost.mMeta.mPublishTs >= beginCreation
&& itPost.mMeta.mPublishTs <= endCreation
&& itPost.mMeta.mMsgFlags == post.mMeta.mMsgFlags
&& itPost.mMeta.mGroupId == post.mMeta.mGroupId
&& itPost.mMeta.mThreadId == post.mMeta.mThreadId
&& itPost.mMeta.mParentId == post.mMeta.mParentId
&& itPost.mMeta.mAuthorId == post.mMeta.mAuthorId
&& itPost.mMeta.mMsgName == post.mMeta.mMsgName
&& itPost.mFiles.size() == post.mFiles.size()
&& itPost.mMeta.mServiceString == post.mMeta.mServiceString
&& itPost.mOlderVersions == post.mOlderVersions
&& itPost.mMsg == post.mMsg )
{
post = itPost;
found = true;
break;
}
}
#ifdef RS_DEEP_SEARCH #ifdef RS_DEEP_SEARCH
if(found) DeepSearch::indexChannelPost(post); if(found) DeepSearch::indexChannelGroup(post);
#endif // RS_DEEP_SEARCH #endif // RS_DEEP_SEARCH
return found; return true;
}
else
return false;
// std::list<RsGxsGroupId> chanIds; chanIds.push_back(post.mMeta.mGroupId);
// std::vector<RsGxsChannelPost> posts;
// std::vector<RsGxsComment> comments;
// if(!getChannelsContent(chanIds, posts, comments)) return false;
//
// /* This is ugly but after digging and doing many tries of doing it the right
// * way ending always into too big refactor chain reaction, I think this is
// * not that bad.
// * The shortcoming of this is that if posts with same data are created in
// * a burst (more then once in a second) is that the id of another similar
// * post could be returned, but this is a pointy case.
// * Order of conditions in the `if` matter for performances */
// bool found = false;
// for(const RsGxsChannelPost& itPost : posts)
// {
// std::cout << __PRETTY_FUNCTION__ << " " << beginCreation << " "
// << itPost.mMeta.mPublishTs << " " << endCreation << " "
// << itPost.mMeta.mMsgId << std::endl;
//
// if( itPost.mMeta.mPublishTs >= beginCreation
// && itPost.mMeta.mPublishTs <= endCreation
// && itPost.mMeta.mMsgFlags == post.mMeta.mMsgFlags
// && itPost.mMeta.mGroupId == post.mMeta.mGroupId
// && itPost.mMeta.mThreadId == post.mMeta.mThreadId
// && itPost.mMeta.mParentId == post.mMeta.mParentId
// && itPost.mMeta.mAuthorId == post.mMeta.mAuthorId
// && itPost.mMeta.mMsgName == post.mMeta.mMsgName
// && itPost.mFiles.size() == post.mFiles.size()
// && itPost.mMeta.mServiceString == post.mMeta.mServiceString
// && itPost.mOlderVersions == post.mOlderVersions
// && itPost.mMsg == post.mMsg )
// {
// post = itPost;
// found = true;
// break;
// }
// }
//
//#ifdef RS_DEEP_SEARCH
// if(found) DeepSearch::indexChannelPost(post);
//#endif // RS_DEEP_SEARCH
//
// return found;
} }