Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep references to all reblogs of a status on home feed #5419

Merged
merged 2 commits into from Oct 16, 2017
Merged

Conversation

Gargron
Copy link
Member

@Gargron Gargron commented Oct 16, 2017

When inserting reblog: Add to set of reblogs of this status on
the feed, if original status was present in the feed, add it to
that set as well.

When removing a reblog: Remove it from that set. Take random
remaining item from the set. If one exists, re-insert it into feed,
otherwise do not re-insert anything.

Fix #4210

@Gargron Gargron added the bug Something isn't working label Oct 16, 2017
Copy link
Contributor

@aschmitz aschmitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments and suggestions. I haven't gotten a chance to look at the test changes in detail.

redis.del(FeedManager.instance.key(:home, account_id))
redis.del(FeedManager.instance.key(:home, account_id, 'reblogs'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, missed that somehow. Good call.

end
end
end

private

def inactive_users
User.confirmed.inactive
@inactive_users ||= User.confirmed.inactive.pluck(:account_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit that this should maybe become inactive_user_ids, but it's only defined in this tiny class, so whatever.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's uh, not substantial.

# If the original status or a reblog of it is within
# REBLOG_FALLOFF statuses from the top, do not re-insert it into
# the feed
rank = redis.zrevrank(timeline_key, status.reblog_of_id)

redis.sadd(reblog_set_key, status.reblog_of_id) unless rank.nil?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this get us anything? I think it might be best to only put reblogs in the reblogs set: if the original status is deleted, the reblogs should go with it (and we should check for that case in unpush), but there's nothing obvious to be gained by tracking the fact that the original status was in the timeline at some point, is there?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the final reblog is deleted, but the original was originally in the feed, we want to re-insert the original - no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't remove the original when we see the reblog (and in fact, we ignore the reblog), so no, we probably don't need to do anything to track the old status, and should move the other sadd to below the return false.

# If the original status or a reblog of it is within
# REBLOG_FALLOFF statuses from the top, do not re-insert it into
# the feed
rank = redis.zrevrank(timeline_key, status.reblog_of_id)

redis.sadd(reblog_set_key, status.reblog_of_id) unless rank.nil?
redis.sadd(reblog_set_key, status.id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're concerned about Redis usage, we can alternatively do this only if another reblog is already within REBLOG_FALLOFF. It requires a bit more logic (to insert the other reblogging status, but only the first time, when creating the set), but doesn't increase Redis usage in the possibly-most-common case of only seeing one reblog.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhhh I don't know what you mean

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to minimize the stuff we add to Redis, we could:

  • Not add to reblog_set_key for the first reblog.
  • Only add to reblog_set_key for the second-or-later reblog.

(I had thought that we'd have to add the original reblog to reblog_set_key, but I actually don't think we would: if it gets deleted, our first move would be to remove it from reblog_set_key anyway. If we do want to track all of the reblogs for a status that a user could see (which would be nice to expose in the UI, but not what this PR appears to be about), then we'd have to add to that set, but for the limited purposes of this PR, we could get away with not creating the extra set in cases where there was only one user-visible reblog for a given status.)

@@ -188,7 +194,7 @@ def add_to_feed(timeline_type, account, status)
# do so if appropriate.
def remove_from_feed(timeline_type, account, status)
timeline_key = key(timeline_type, account.id)
reblog_key = key(timeline_type, account.id, 'reblogs')
reblog_key = key(timeline_type, account.id, 'reblogs')

if status.reblog?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should handle the case where status.reblog? == false and unconditionally delete the reblog_set_key, I think? If a status is deleted, we can safely toss all reblogs of it. (I don't actually know what happens right now in the case where we only have a reblog in our feed and the original is deleted, but it might be worth looking into.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True

When inserting reblog: Add to set of reblogs of this status on
the feed, if original status was present in the feed, add it to
that set as well.

When removing a reblog: Remove it from that set. Take random
remaining item from the set. If one exists, re-insert it into feed,
otherwise do not re-insert anything.

Fix #4210
@Gargron
Copy link
Member Author

Gargron commented Oct 16, 2017

@aschmitz Can we merge this and you submit a PR with patches you suggested? I'm.. really tired.. 😩

@aschmitz
Copy link
Contributor

aschmitz commented Oct 16, 2017 via email

@Gargron Gargron merged commit 3411816 into master Oct 16, 2017
@Gargron Gargron deleted the fix-unreblogs branch October 16, 2017 18:44
aschmitz added a commit to aschmitz/mastodon that referenced this pull request Oct 17, 2017
Builds on mastodon#5419, with a few minor optimizations and cleanup of sets
after they are no longer needed.
Gargron pushed a commit that referenced this pull request Oct 17, 2017
* Clean up reblog-tracking sets from FeedManager

Builds on #5419, with a few minor optimizations and cleanup of sets
after they are no longer needed.

* Update tests, fix multiply-reblogged case

Previously, we would have lost the fact that a given status was
reblogged if the displayed reblog of it was removed, now we don't.

Also added tests to make sure FeedManager#trim cleans up our reblog
tracking keys, fixed up FeedCleanupScheduler to use the right loop,
and fixed the test for it.
cobodo pushed a commit to cobodo/mastodon that referenced this pull request Oct 20, 2017
* Keep references to all reblogs of a status on home feed

When inserting reblog: Add to set of reblogs of this status on
the feed, if original status was present in the feed, add it to
that set as well.

When removing a reblog: Remove it from that set. Take random
remaining item from the set. If one exists, re-insert it into feed,
otherwise do not re-insert anything.

Fix mastodon#4210

* When original is removed, toss out reblog references
cobodo pushed a commit to cobodo/mastodon that referenced this pull request Oct 20, 2017
* Clean up reblog-tracking sets from FeedManager

Builds on mastodon#5419, with a few minor optimizations and cleanup of sets
after they are no longer needed.

* Update tests, fix multiply-reblogged case

Previously, we would have lost the fact that a given status was
reblogged if the displayed reblog of it was removed, now we don't.

Also added tests to make sure FeedManager#trim cleans up our reblog
tracking keys, fixed up FeedCleanupScheduler to use the right loop,
and fixed the test for it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants