diff --git a/libretroshare/src/gxs/rsdataservice.cc b/libretroshare/src/gxs/rsdataservice.cc index 4c8044e1c..2511f53d4 100644 --- a/libretroshare/src/gxs/rsdataservice.cc +++ b/libretroshare/src/gxs/rsdataservice.cc @@ -311,6 +311,7 @@ RsGxsGrpMetaData* RsDataService::locked_getGrpMeta(RetroCursor &c) grpMeta->mPublishTs = c.getInt32(COL_TIME_STAMP); grpMeta->mGroupFlags = c.getInt32(COL_NXS_FLAGS); + grpMeta->mGrpSize = c.getInt32(COL_NXS_FILE_LEN); offset = 0; @@ -441,7 +442,7 @@ RsGxsMsgMetaData* RsDataService::locked_getMsgMeta(RetroCursor &c) offset = 0; data = (char*)c.getData(COL_SIGN_SET, data_len); msgMeta->signSet.GetTlv(data, data_len, &offset); - + msgMeta->mMsgSize = c.getInt32(COL_NXS_FILE_LEN); msgMeta->mMsgFlags = c.getInt32(COL_NXS_FLAGS); msgMeta->mPublishTs = c.getInt32(COL_TIME_STAMP); diff --git a/libretroshare/src/gxs/rsgxsdata.h b/libretroshare/src/gxs/rsgxsdata.h index 5e804e5e7..2835861d0 100644 --- a/libretroshare/src/gxs/rsgxsdata.h +++ b/libretroshare/src/gxs/rsgxsdata.h @@ -75,6 +75,7 @@ public: uint32_t mMsgCount; // ??? uint32_t mLastPost; // ??? uint32_t mReputationCutOff; + uint32_t mGrpSize; uint32_t mGroupStatus; uint32_t mRecvTS; @@ -116,6 +117,7 @@ public: // normally READ / UNREAD flags. LOCAL Data. uint32_t mMsgStatus; + uint32_t mMsgSize; time_t mChildTs; uint32_t recvTS; RsFileHash mHash; diff --git a/libretroshare/src/gxs/rsgxsdataaccess.cc b/libretroshare/src/gxs/rsgxsdataaccess.cc index 550dc723c..517be721a 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.cc +++ b/libretroshare/src/gxs/rsgxsdataaccess.cc @@ -1435,6 +1435,55 @@ bool RsGxsDataAccess::getMsgRelatedInfo(MsgRelatedInfoReq *req) return true; } +bool RsGxsDataAccess::getGroupStatistic(GroupStatisticRequest *req) +{ + // filter based on options + GxsMsgIdResult metaReq; + metaReq[req->mGrpId] = std::vector(); + GxsMsgMetaResult metaResult; + mDataStore->retrieveGxsMsgMetaData(metaReq, metaResult); + + std::vector& msgMetaV = metaResult[req->mGrpId]; + + req->mGroupStatistic.mNumMsgs = msgMetaV.size(); + req->mGroupStatistic.mTotalSizeOfMsgs = 0; + for(int i = 0; i < msgMetaV.size(); i++) + { + RsGxsMsgMetaData* m = msgMetaV[i]; + req->mGroupStatistic.mTotalSizeOfMsgs += m->mMsgSize + m->serial_size(); + } + return true; +} + +// potentially very expensive! +bool RsGxsDataAccess::getServiceStatistic(ServiceStatisticRequest *req) +{ + std::map grpMeta; + + mDataStore->retrieveGxsGrpMetaData(grpMeta); + + std::map::iterator mit = grpMeta.begin(); + + req->mServiceStatistic.mNumGrps = grpMeta.size(); + req->mServiceStatistic.mSizeOfGrps = 0; + req->mServiceStatistic.mSizeOfMsgs = 0; + + for(; mit != grpMeta.end(); mit++) + { + RsGxsGrpMetaData* m = mit->second; + req->mServiceStatistic.mSizeOfGrps += m->mGrpSize + m->serial_size(); + GroupStatisticRequest gr; + gr.mGrpId = m->mGroupId; + getGroupStatistic(&gr); + req->mServiceStatistic.mNumMsgs += gr.mGroupStatistic.mNumMsgs; + req->mServiceStatistic.mSizeOfMsgs += gr.mGroupStatistic.mTotalSizeOfMsgs; + } + + req->mServiceStatistic.mSizeStore = req->mServiceStatistic.mSizeOfGrps + req->mServiceStatistic.mSizeOfMsgs; + + return true; +} + bool RsGxsDataAccess::getMsgList(MsgIdReq* req) { diff --git a/libretroshare/src/gxs/rsgxsdataaccess.h b/libretroshare/src/gxs/rsgxsdataaccess.h index 7efa19516..3c32d8d10 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.h +++ b/libretroshare/src/gxs/rsgxsdataaccess.h @@ -399,12 +399,26 @@ private: /*! * Attempts to retrieve messages related to msgIds of associated equest - * @param token request token to be redeemed - * @param msgIds + * @param req Request object to satisfy * @return false if data cannot be found for token */ bool getMsgRelatedInfo(MsgRelatedInfoReq* req); + + /*! + * + * Attempts to retrieve group statistic + * @param req Request object to satisfy + */ + bool getGroupStatistic(GroupStatisticRequest* req); + + /*! + * + * Attempts to service statistic + * @param req request object to satisfy + */ + bool getServiceStatistic(ServiceStatisticRequest* req); + /*! * This filter msgs based of options supplied (at the moment just status masks) * @param msgIds The msgsIds to filter