have GxsChannelPostItem only keep a copy of the group meta data instead of the full group data to save memory

This commit is contained in:
csoler 2020-04-18 13:45:55 +02:00
parent 678bcf5830
commit 2a046eacb3
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 16 additions and 15 deletions

View File

@ -44,11 +44,12 @@
* #define DEBUG_ITEM 1
****/
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelGroup& group, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate,const std::set<RsGxsMessageId>& older_versions) :
GxsFeedItem(feedHolder, feedId, group.mMeta.mGroupId, messageId, isHome, rsGxsChannels, autoUpdate), mGroup(group) // this one should be in GxsFeedItem
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData& group_meta, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate,const std::set<RsGxsMessageId>& older_versions) :
GxsFeedItem(feedHolder, feedId, group_meta.mGroupId, messageId, isHome, rsGxsChannels, autoUpdate),
mGroupMeta(group_meta)
{
mPost.mMeta.mMsgId = messageId; // useful for uniqueIdentifer() before the post is loaded
mPost.mMeta.mGroupId = group.mMeta.mGroupId;
mPost.mMeta.mGroupId = mGroupMeta.mGroupId;
QVector<RsGxsMessageId> v;
//bool self = false;
@ -62,7 +63,7 @@ GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId,
setMessageVersions(v) ;
setup();
//init(messageId,older_versions) ;
// no call to loadGroup() here because we have it already.
}
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId& groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate,const std::set<RsGxsMessageId>& older_versions) :
@ -238,7 +239,7 @@ QString GxsChannelPostItem::getMsgLabel()
QString GxsChannelPostItem::groupName()
{
return QString::fromUtf8(mGroup.mMeta.mGroupName.c_str());
return QString::fromUtf8(mGroupMeta.mGroupName.c_str());
}
void GxsChannelPostItem::loadComments()
@ -384,7 +385,7 @@ void GxsChannelPostItem::fill()
ui->logoLabel->setPixmap(thumbnail);
}
if( !IS_GROUP_PUBLISHER(mGroup.mMeta.mSubscribeFlags) )
if( !IS_GROUP_PUBLISHER(mGroupMeta.mSubscribeFlags) )
ui->editButton->hide() ;
if (!mIsHome)
@ -401,7 +402,7 @@ void GxsChannelPostItem::fill()
RetroShareLink msgLink = RetroShareLink::createGxsMessageLink(RetroShareLink::TYPE_CHANNEL, mPost.mMeta.mGroupId, mPost.mMeta.mMsgId, messageName());
//ui->subjectLabel->setText(msgLink.toHtml());
if (IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroup.mMeta.mSubscribeFlags))
if (IS_GROUP_SUBSCRIBED(mGroupMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroupMeta.mSubscribeFlags))
{
ui->unsubscribeButton->setEnabled(true);
}
@ -440,7 +441,7 @@ void GxsChannelPostItem::fill()
ui->unsubscribeButton->hide();
ui->copyLinkButton->show();
if (IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroup.mMeta.mSubscribeFlags))
if (IS_GROUP_SUBSCRIBED(mGroupMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroupMeta.mSubscribeFlags))
{
ui->readButton->setVisible(true);
@ -753,7 +754,7 @@ void GxsChannelPostItem::download()
void GxsChannelPostItem::edit()
{
CreateGxsChannelMsg *msgDialog = new CreateGxsChannelMsg(mGroup.mMeta.mGroupId,mPost.mMeta.mMsgId);
CreateGxsChannelMsg *msgDialog = new CreateGxsChannelMsg(mGroupMeta.mGroupId,mPost.mMeta.mMsgId);
msgDialog->show();
}
@ -823,7 +824,7 @@ void GxsChannelPostItem::loadGroup()
std::vector<RsGxsChannelGroup> groups;
const std::list<RsGxsGroupId> groupIds = { groupId() };
if(!rsGxsChannels->getChannelsInfo(groupIds,groups))
if(!rsGxsChannels->getChannelsInfo(groupIds,groups)) // would be better to call channel Summaries for a single group
{
RsErr() << "GxsGxsChannelGroupItem::loadGroup() ERROR getting data" << std::endl;
return;
@ -843,7 +844,7 @@ void GxsChannelPostItem::loadGroup()
* thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete */
mGroup = group;
mGroupMeta = group.mMeta;
}, this );
});

View File

@ -47,7 +47,7 @@ public:
// This one is used in channel thread widget. We don't want the group data to reload at every post, so we load it in the hosting
// GxsChannelsPostsWidget and pass it to created items.
GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelGroup& group, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate, const std::set<RsGxsMessageId>& older_versions = std::set<RsGxsMessageId>());
GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGroupMetaData& group, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate, const std::set<RsGxsMessageId>& older_versions = std::set<RsGxsMessageId>());
// // This method can be called when additional information is known about the post. In this case, the widget will be initialized with some
// // minimap information from the post and completed when the use displays it, which shouldn't cost anything more.
@ -124,7 +124,7 @@ private:
bool mCloseOnRead;
bool mLoaded;
RsGxsChannelGroup mGroup;
RsGroupMetaData mGroupMeta;
RsGxsChannelPost mPost;
std::list<SubFileItem*> mFileItems;

View File

@ -520,7 +520,7 @@ void GxsChannelPostsWidget::createPostItem(const RsGxsChannelPost& post, bool re
older_versions.insert(meta.mMsgId);
GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, mGroup,meta.mMsgId, true, false,older_versions);
GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, mGroup.mMeta,meta.mMsgId, true, false,older_versions);
ui->feedWidget->addFeedItem(item, ROLE_PUBLISH, QDateTime::fromTime_t(meta.mPublishTs));
return ;
@ -539,7 +539,7 @@ void GxsChannelPostsWidget::createPostItem(const RsGxsChannelPost& post, bool re
}
else
{
GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, mGroup,meta.mMsgId, true, true);
GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, mGroup.mMeta,meta.mMsgId, true, true);
ui->feedWidget->addFeedItem(item, ROLE_PUBLISH, QDateTime::fromTime_t(meta.mPublishTs));
}