Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

[ASRangeController] properly update _rangeTypeIndexPaths when adding/removing index paths and sections#1054

Closed
knopp wants to merge 3 commits intofacebookarchive:masterfrom
knopp:upstream
Closed

[ASRangeController] properly update _rangeTypeIndexPaths when adding/removing index paths and sections#1054
knopp wants to merge 3 commits intofacebookarchive:masterfrom
knopp:upstream

Conversation

@knopp
Copy link
Copy Markdown
Contributor

@knopp knopp commented Jan 11, 2016

This fixes #1028

…dexPaths prior to them

Signed-off-by: Matej Knopp <matej.knopp@gmail.com>
Signed-off-by: Matej Knopp <matej.knopp@gmail.com>
@appleguy
Copy link
Copy Markdown
Contributor

@knopp thanks a lot, I can't tell you how awesome it is to have your help here - especially in the production implementation, as I'm hoping to get the Beta working well enough in the next several weeks, but still it will be a riskier direction for any production apps than fixing any holes in the Stable version.

@appleguy appleguy added the Bug label Jan 11, 2016
@appleguy appleguy added this to the 1.9.5 milestone Jan 11, 2016
@appleguy
Copy link
Copy Markdown
Contributor

This issue is avoided by the recompute-everything architecture of the Beta controller, right?

We are starting work soon on asynchronously applying the Display and FetchData ranges in the Beta version, on top of really substantial performance improvements I landed recently (I'd made a couple pretty stupid mistakes that just hadn't been tested through yet). You might try out Beta in your code and let me know if there are any immediate problems you detect.

@knopp
Copy link
Copy Markdown
Contributor Author

knopp commented Jan 11, 2016

@appleguy, in a way this is also an issue with ASRangeControllerBeta, because you store _allPreviousIndexPaths between _updateVisibleNodeIndexPaths invocations. When adding / removing nodes, the index paths in _allPreviousIndexPaths become stale and may point to items no longer existing data controller.

…ontroller is updating

Signed-off-by: Matej Knopp <matej.knopp@gmail.com>
@appleguy
Copy link
Copy Markdown
Contributor

@knopp aha, ok. Yes I actually ran into that but fixed it by handling nil nodes and skipping over them in the Beta controller, so I'm pretty sure that is a stable / correct behavior for the newer one. Most important thing now is getting a new release out to fix this.

@knopp
Copy link
Copy Markdown
Contributor Author

knopp commented Jan 13, 2016

@appleguy, which commit are you referring to? Also, are you sure that merely handling nil nodes is correct? When adding / removing nodes, the index paths in _allPreviousIndexPaths may simply point to wrong nodes, but still be non null. So even if it doesn't crash, it won't behave correctly.

I think there are two possible solutions - either do what I did in the branch - update _allPreviousIndexPaths every time the data controller adds/removes nodes/sections, or simply discard _allPreviousIndexPaths when adding/removing and next time _updateVisibleNodeIndexPaths is called, iterate over all nodes from data source.

@appleguy
Copy link
Copy Markdown
Contributor

@knopp are you sure it won't behave correctly in the *Beta version? Very very interested in your thoughts there. For each index path, we independently check if it currently lies within each range. I think that should be sufficient, but I have not yet deeply considered this _editing vs _completed nodes issue. _editingExternalNodes was added after my original refactor of ASDataController and I'm actually pretty concerned about it, and will evaluate if it is possible to re-simplify some of that stuff.

For this diff, do you have any test apps / test cases that you used? I want to get a fix for this issue out as quickly as possible, and I would believe that this approach addresses conditions that #1060 does not, but I am worried about pushing this out with minimal testing. Is there a scenario you can describe that does in fact break #1060 (or more importantly, *Beta, because it will become Stable within a couple weeks), but is addressed by this change?

@knopp
Copy link
Copy Markdown
Contributor Author

knopp commented Jan 14, 2016

@appleguy, here is project that is broken with current ASRangeController but works with this pull request: https://github.com/tomizimobile/ASDKSearchIssue

Regarding ASRangeControllerBeta: Each index path (allIndexPaths) that you check belongs to union of fetch, display, visible and _allPreviousIndexPaths. Now consider following scenario:

We have node[0,0] that is visible, and appropriate indexPath [0,0] is in _allPreviousIndexPaths; Let's call it original node;

Now this happens between invocations of _updateVisibleNodeIndexPaths

  1. New node is added to [0,0]; This causes original node index path [0,0] to become [0,1].(_allPreviousIndexPaths doesn't change in any way though and still contains [0,0])
  2. Collection view is instantly scrolled in a way where section 0 is no longer in fetch, display or visible;

The original node is still marked as visible, even though it no longer is. That is because the union of fetch, display, visible and _allPreviousIndexPaths contains [0,0]. But original node is no longer [0,0], it is now [0,1] (because another node was added to [0,0]. So the original node is missed while iterating allIndexPaths and not updated.

@appleguy appleguy modified the milestones: 1.9.6, 1.9.5 Jan 17, 2016
@knopp
Copy link
Copy Markdown
Contributor Author

knopp commented Jan 20, 2016

It's probably not worth committing this. ASRangeControllerStable has other issues as well, so let's focus on ASRangeControllerBeta instead.

@appleguy
Copy link
Copy Markdown
Contributor

@knopp ok, I'll take your advice. I tend to agree insofar as there is risk in changing code that is this fragile.

@appleguy appleguy closed this Jan 23, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ASRangeController] Old range controller (current stable 1.9.4 release) issue when deleting items.

3 participants