fix(Timeline): double content changed calls #1012
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
on_content_changed runs when the content has changed. While it does run when the model's items change, it would also run at the end of requesting a page.
From what I can remember that was so we dealt with empty timelines, aka, when the request ends successfully but the model wasn't changed as there are no items in the timeline.
on_content_changed main use, while virtual, is to change the base status: are there any items? show the timeline, are there no items? show the empty state, is there an error? show the error view. So if it was ran multiple times it wouldnt have any noticeable effect.
But, at some point in 0.7, I added mass relationship requests. Instead of requesting every single account's relationship status, we can now do many at once, thus avoiding spamming the instance. This is done with a container view that overrides on_content_changed, so it requests the new relationships when new items are added/removed.
Since it would be called twice however, that would mean double the mass relationship requests, even though it was useless. So now to avoid the second
on_content_changed
, it only gets called when no items were added to the model.For anyone more interested, yes, there are checks in place to avoid unnecessary mass relationship requests, by checking if accounts had already gotten their relationships. However, since both on_content_changed requests happened right after the other one, the first one didn't get the chance to finish.