Skip to content
New issue

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

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

Already on GitHub? # to your account

feat(graphql): Configurable option to deduplicate pollers #1451

Merged
merged 2 commits into from
Aug 5, 2024

Conversation

kvenn
Copy link
Contributor

@kvenn kvenn commented Aug 4, 2024

Problem

If you call startPolling 10 times for the same request, it'll start 10 pollers that are all doing the same thing.

Solution

  • Allow consumers to specify if they'd like deduplication (defaults to false for backwards compatibility)
  • When a new poller is added, if it's a shorter duration than the previous one for that identical request, it'll update to use the new time
    • If that faster poller is removed, it'll fallback to the next fastest time
    • If all pollers for a request are removed, it doesn't poll

Testing

    final obs5 = _client.friendRequests(_onMyFriendRequests);
    final obs10 = _client.friendRequests(_onMyFriendRequests);
    final obs3 = _client.friendRequests(_onMyFriendRequests);
    final obs15 = _client.friendRequests(_onMyFriendRequests);

    obs5.startPolling(const Duration(seconds: 5));
    obs10.startPolling(const Duration(seconds: 10));
    obs3.startPolling(const Duration(seconds: 3));
    obs15.startPolling(const Duration(seconds: 15));
    // Should settle at 3 seconds (fastest)

    // Wait 10 seconds to confirm pollers only every 3 seconds
    Future.delayed(const Duration(seconds: 7)).then((_) {
      print('------------------TEST------------------');
      obs3.stopPolling();
      // Duration should now be 5 seconds
    });
    // Confirm it's 5 (should see 3 or 4 of them)
    Future.delayed(const Duration(seconds: 20)).then((_) {
      print('------------------TEST------------------');
      obs5.close();
      // Duration should now be 10 seconds
    });

Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

LGTM, would be good to add some kind of docs but this can be a followup PR

@vincenzopalazzo vincenzopalazzo merged commit e68adbe into zino-hofmann:main Aug 5, 2024
4 checks passed
@kvenn kvenn deleted the dedup-poller-zino branch August 5, 2024 19:40
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants