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

feat: Pagination on Consent Load #307

Merged
merged 3 commits into from
Apr 9, 2024
Merged

feat: Pagination on Consent Load #307

merged 3 commits into from
Apr 9, 2024

Conversation

alexrisch
Copy link
Contributor

@alexrisch alexrisch commented Apr 4, 2024

Added optional pagination to consent list loading

@alexrisch
Copy link
Contributor Author

Just using for verifying a case

@nplasterer
Copy link
Contributor

We could make the 2k wallet on the dev network have a bunch of consent records to test this as well?

@alexrisch
Copy link
Contributor Author

We could make the 2k wallet on the dev network have a bunch of consent records to test this as well?

We can, was working with Daria and she had a similar wallet to the one seeing a problem and it didn't seem specific to that use case. However it could be ideal to make the 2k wallet have additional consent records for testing this and verifying performance in the future

@alexrisch
Copy link
Contributor Author

I've added a couple thousand consent entries on to the dev wallet, this will make testing a little more real in the future

Added pagination to consent refresh call
@alexrisch alexrisch marked this pull request as ready for review April 5, 2024 22:51
@alexrisch alexrisch requested a review from a team as a code owner April 5, 2024 22:51
@alexrisch alexrisch changed the title Added test for consent list loading feat: Pagination on Consent Load Apr 5, 2024
Sources/XMTPiOS/Contacts.swift Outdated Show resolved Hide resolved
Tests/XMTPTests/ContactsTests.swift Outdated Show resolved Hide resolved
guard let identifier = identifier else {
throw ContactError.invalidIdentifier
}

let envelopes = try await client.apiClient.envelopes(topic: Topic.preferenceList(identifier).description, pagination: Pagination(direction: .ascending))
let pagination = pagination ?? Pagination(direction: .ascending)
let envelopes = try await client.apiClient.envelopes(topic: Topic.preferenceList(identifier).description, pagination: pagination)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this already paginated under the hood?

What problem are we solving by putting the user in control of pagination here? When would they want to do anything other than load the entire consent list? Anything less would leave them in an out of date state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to only take an after date to allow for more performant local cache updates

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there needs to be a bigger change here because the refreshConsentList just wipes out the current list and makes a new list. I think the ideal scenario is that the consentList doesn't get reset. On every load and that you could just fetch the latest consent items from the last time that you fetched consent. But I think you'll need more changes for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is kinda my issue with current consent, I think it's nuanced (at least personally)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An integrator would only use afterDate if they were caching the consent list, so they likely would not be using the SDK memory cached consent list after refreshing

Copy link
Contributor

@neekolas neekolas Apr 6, 2024

Choose a reason for hiding this comment

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

An integrator would only use afterDate if they were caching the consent list

Ahh. I see. But our SDK also needs an up-to-date consent list, doesn't it? Is the idea that the integrator would pass their known entries back in to us from their cache on startup?

Alternatively, we could just handle caching for the integrator. I know on iOS there's all kinds of permissions implications to handling persistence, but maybe it's worthwhile anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm ya I think we still need to keep an up to date consent list. I'd suggest we handle the caching like we do for conversations in the conversations class https://github.com/xmtp/xmtp-ios/blob/main/Sources/XMTPiOS/Conversations.swift#L57 We could probably open an issue for a follow up if you think that will take too much time. The problem is if that list doesn't reflect correctly calling things like isAllowed which just checks the cached list will return incorrectly. Do they not call any of those methods?

Alternatively in the mean time if they literally just take the list and put it straight into the database we could keep refreshConsentList() as is. That way it's still always resetting the cached list which is what other integrators expect and then add pagination just to the load method and make it public kind of like your first approach. Then they could just call load directly and there would be no expectation of using the convenience methods like isAllowed without first calling refreshConsentList. Does that make sense?

I don't think the caching should take that much time but just giving some options.

}
}

return consentList
return Array(entries.values)
Copy link
Contributor

Choose a reason for hiding this comment

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

What does entries.values return if not an array. 🤔

Sources/XMTPiOS/Contacts.swift Outdated Show resolved Hide resolved
Sources/XMTPiOS/Contacts.swift Outdated Show resolved Hide resolved
@alexrisch alexrisch force-pushed the ar/consent-test branch 2 times, most recently from fd73890 to 019da92 Compare April 9, 2024 22:36
Copy link
Contributor

@nplasterer nplasterer left a comment

Choose a reason for hiding this comment

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

Approving to unblock. Don't forget to bump the Pod file so you can make a release.

Added Caching for Consent List
Updated allow/deny calls to only call network once
@alexrisch alexrisch merged commit d27dd5a into main Apr 9, 2024
2 checks passed
@alexrisch alexrisch deleted the ar/consent-test branch April 9, 2024 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants