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

Make sure collection have unique ListDiffable objects on initial data… #993

Closed
wants to merge 7 commits into from

Conversation

yemodin
Copy link
Contributor

@yemodin yemodin commented Oct 29, 2017

… source setup too

Changes in this pull request

Issue fixed: #815

Checklist

  • All tests pass. Demo project builds and runs.
  • I added tests, an experiment, or detailed why my change isn't tested.
  • I added an entry to the CHANGELOG.md for any breaking changes, enhancements, or bug fixes.
  • I have reviewed the contributing guide

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@yemodin
Copy link
Contributor Author

yemodin commented Oct 29, 2017

@rnystrom can we use something like this for #815? Or better handle this at AdapterUpdater?

@yemodin
Copy link
Contributor Author

yemodin commented Oct 29, 2017

Not sure about logic behind this test, when started separately looks like it always fails

XCTAssertEqual(descriptions.count, 4);

@facebook-github-bot
Copy link
Contributor

@yemodin has updated the pull request. View: changes

@facebook-github-bot
Copy link
Contributor

@yemodin has updated the pull request. View: changes

Actually throw on removed test "test_whenPassingNonUniqueIdentifiers_adapterShouldAssert" make extra one description hanging around
@facebook-github-bot
Copy link
Contributor

@yemodin has updated the pull request. View: changes

}
#endif

NSArray *uniqueObjects = objectsWithDuplicateIdentifiersRemoved(objects);
Copy link
Contributor

Choose a reason for hiding this comment

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

While not opposed to this change, this does make deduping in the updater redundant.

Maybe instead the deduping should be done here:

https://github.com/Instagram/IGListKit/blob/master/Source/IGListAdapter.m#L146

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rnystrom If I dedupe at https://github.com/Instagram/IGListKit/blob/master/Source/IGListAdapter.m#L146 we still have the same issue reappear on reloadDataWithCompletion for adapter:

[weakSelf updateObjects:newItems dataSource:dataSource];

Copy link
Contributor

Choose a reason for hiding this comment

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

Oooooooh, now I see it! Wo this is an awesome find @yemodin! How about we:

I actually want to move object generation entirely so that "to" object arrays are only constructed once. Atm they are built w/ every call to performUpdatesAnimated:completion:, even if a bunch of calls are updated into a single batch.

Copy link
Contributor Author

@yemodin yemodin Nov 6, 2017

Choose a reason for hiding this comment

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

Done. Also made deduping before performUpdatesAnimated

NSArray *newObjects = [dataSource objectsForListAdapter:self];

And test for such case.

Added test for updates
@facebook-github-bot
Copy link
Contributor

@yemodin has updated the pull request. View: changes

@rnystrom rnystrom added this to the 3.2.0 milestone Nov 6, 2017
@facebook-github-bot
Copy link
Contributor

@yemodin has updated the pull request. View: changes

@rnystrom
Copy link
Contributor

rnystrom commented Nov 7, 2017

@yemodin would love to import this, but we still need you to sign the CLA, then we're good to go! https://code.facebook.com/cla

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@@ -319,14 +321,14 @@ - (void)performUpdatesAnimated:(BOOL)animated completion:(IGListUpdaterCompletio
}

NSArray *fromObjects = self.sectionMap.objects;
NSArray *newObjects = [dataSource objectsForListAdapter:self];
NSArray *uniqueObjects = objectsWithDuplicateIdentifiersRemoved([dataSource objectsForListAdapter:self]);
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're going to put this here (which we don't need to yet), we should remove it from here since that'll be wasteful. I lean towards not messing w/ it here since it'll be extra work (dedupe every update call instead of at coalescence).

I'm actually going to patch that change then import this!

@facebook-github-bot
Copy link
Contributor

@yemodin has updated the pull request. View: changes

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@rnystrom has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@rnystrom
Copy link
Contributor

rnystrom commented Nov 8, 2017

Internal CI is reporting a test failure for -[IGListAdapterTests test_whenPassingNonUniqueIdentifiers_adapterUpdatesShouldSkipDuplicates]. I'll need to figure out what's going on there before we can land.

@yemodin
Copy link
Contributor Author

yemodin commented Nov 8, 2017

@rnystrom It fails because "revert dedupe in performUpdatesAnimated". If only set objects twice and perform update on adapter it will pass duplicates too

@drinkius
Copy link

drinkius commented Nov 9, 2017

Is this pull request going to be merged to master? Currently in our project we face an issue with the Identifiers must be unique! assert, in our setup having several object with the same IDs is expected and having this Assert doesn't bring much value

@yemodin
Copy link
Contributor Author

yemodin commented Nov 9, 2017

@rnystrom Should I return dedupe to performUpdatesAnimated? Let me know if we have better options.

@rnystrom
Copy link
Contributor

rnystrom commented Nov 9, 2017

@drinkius it'll be in master momentarily. Bear in mind that this will assert more if your objects aren't unique. The assert isn't going away. In fact, your objects w/ duped IDs are being stripped.

@yemodin no worries! Patching internally then landing 😄

@drinkius
Copy link

drinkius commented Nov 9, 2017

@rnystrom From what I see in the current implementation in @yemodin 's repo it just strips the duplicates (I indeed need this behaviour) but you can continue working well with the stripped list, is it going to change?

@rnystrom
Copy link
Contributor

rnystrom commented Nov 9, 2017

Nope, this PR adds deduping to a few places where it was missing and causing inconsistencies. The assert is staying put tho as a warning to the developer that the data you're putting into IGLK isn't what you're going to see.

@rnystrom
Copy link
Contributor

Need to unland and re-evaluate, this caused some regressions internally

@rnystrom
Copy link
Contributor

False alarm, something else started crashing in a similar spot at almost the exact same time. Will be reverting my revert this week 😅

facebook-github-bot pushed a commit that referenced this pull request Nov 21, 2017
Summary:
… source setup too

Issue fixed: #815

- [x] All tests pass. Demo project builds and runs.
- [x] I added tests, an experiment, or detailed why my change isn't tested.
- [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes.
- [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md)
Closes #993

Reviewed By: manicakes

Differential Revision: D6388270

Pulled By: rnystrom

fbshipit-source-id: e5e7e047bad5f21b81b562ebd586f7f5036325ff
@jessesquires jessesquires reopened this Nov 24, 2017
@jessesquires
Copy link
Contributor

@rnystrom -- re-opened this so we don't loose track. close once you successfully un-revert? 😄

@rnystrom
Copy link
Contributor

Added in c7d4dc2

@rnystrom rnystrom closed this Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate why Swift objects with duped identifiers can appear more than once
5 participants