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

Migrate /chatters commands to use Helix api #4088

Merged
merged 37 commits into from
Nov 1, 2022

Conversation

cbclemmer
Copy link
Contributor

@cbclemmer cbclemmer commented Oct 29, 2022

Pull request checklist:

  • CHANGELOG.md was updated, if applicable

Description

closes #4019

Features:

  • Migrates /chatters command will use helix api or cache
    • If the user is neither mod or broadcaster the list is taken from the user list cache
    • If the user has mod rights the list is taken from the chat/chatters helix api command
  • The old irc commands for /chatters have been removed based on comment in issue

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 36. Check the log or trigger a new build to see more.

src/common/ChatterSet.cpp Outdated Show resolved Hide resolved
src/controllers/commands/CommandController.cpp Outdated Show resolved Hide resolved
src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
Copy link
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

These changes are both pretty heavy, and while they rely on the same underlying functionality (the cursor-pages-fetching thing), it would be a lot easier to review if I could focus on a single functionality rather than two, since most feedback I have would apply to both.

So in short, could you undo the changes either to the /mods command or to the /chatters command (I have no preference) in this PR?

After that's done, I will go ahead and review the code and come with more proper/full feedback

EDIT: btw, feel free to ignore clang-tidy for now, it can come with some weird suggestions :)

@cbclemmer
Copy link
Contributor Author

@pajlada I totally understand. The only reason I did it this way was because I needed both /mods and /chatters to make the the viewer list be entirely moved to the Helix api. I'll just separate this into /mods and /chatters prs and then once both are merged I'll add a pr that migrates the viewer list.

@cbclemmer cbclemmer changed the title Migrate /mods and /chatters commands to use helix api Migrate /chatters commands to use helix api Oct 30, 2022
@cbclemmer
Copy link
Contributor Author

@pajlada Code and pr message has been updated. I've got everything in another branch to merge in later. There were a few functions that will be shared for /chatters and /mods so some functions look like they shouldn't be their own thing, but they'll be useful later.

src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
src/providers/twitch/TwitchChannel.cpp Outdated Show resolved Hide resolved
src/controllers/commands/CommandController.cpp Outdated Show resolved Hide resolved
src/controllers/commands/CommandController.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.hpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.hpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
@cbclemmer
Copy link
Contributor Author

@pajlada I changed the helper function for helix to be a more generalized version of makeRequest that can be paginated or not. I'll use this for the /mods pr too. It now can pass in a function that does what it needs to the response from the api and can recursively loop until the end of the list. The /chatters command now just gets one page of chat/chatters api and returns the the total property value. I also changed the error type to be a general error because there isn't any special error types with these requests.

cbclemmer and others added 7 commits November 1, 2022 09:46
I did this by running the ./tools/clang-format-all.sh script
The number in the parenthesis should link to the PR that implements the change, which is 4088 in this case
This makes the code readable, and if you need to know the exact type
your IDE can hint it at you (or you can check the getChatters function definition)
This makes the diff a teeny tiny bit easier to go through
src/controllers/commands/CommandController.cpp Outdated Show resolved Hide resolved
src/controllers/commands/CommandController.cpp Outdated Show resolved Hide resolved
src/controllers/commands/CommandController.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Outdated Show resolved Hide resolved
src/providers/twitch/api/Helix.hpp Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Instead of having a shared method to handle the pagination logic, this
adds a private `fetchChatters` method that expects the caller to
provide all parameters that would be necessary to make the request.
This method can then be used from the public-facing `getChatters` method
in a recursive manner, while also keeping the error handling code right
in that function.

With this change, the success result type has been changed to the
`HelixChatters` type (the same used in the private method). By doing
this, we can provide a consistent & full API for any users of the
`getChatters` API and not have to provide a separate API for the
`/chatters` function.

Other important changes that came with this was also avoiding the use of
raw pointers, the previous code had difficult-to-track pointers & memory
leaks for every call that was made (chatterList and page).

One potential unbenchmarked downside to the refactored implementation is
that we make more sets of users instead of adding them straight onto the
same one. This is a concession that is worth it in my opinion as it
makes the implementation easier to read. If the code was used in some
hot spot we can benchmark and reconsider this.

Another bonus change added to this feature is that we fetch 1000
chatters per page using the `first` request query parameter, making us
use a lot fewer API requests. This means we'll run less functions
recursively and worry less about crashing our stack.
@pajlada
Copy link
Member

pajlada commented Nov 1, 2022

@cbclemmer uno reverse card - I committed some stuff to your PR that I'd like you to review/approve. Most commits are small and do very little, they'd be easy to go through and it's easy to understand why. However, I made a big refactor PR for the pagination logic to change the pattern we use. This changes the pattern for paginated requests in this PR and for future paginated requests to need two functions; 1 public one that users (e.g. CommandController or TwitchChannel) can use which has a simple, single-use API and 1 private one that the public function will use & recursively call.
The big refactor commit can be found here a3aed80 (#4088) and has a commit message where I try to explain all of the changes I made and why.

Let me know if you have any questions!

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

src/providers/twitch/api/Helix.cpp Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Show resolved Hide resolved
src/providers/twitch/api/Helix.cpp Show resolved Hide resolved
tests/src/HighlightController.cpp Show resolved Hide resolved
@cbclemmer
Copy link
Contributor Author

@pajlada That all looks good. The reason I wanted to try to make a more general request was because the handling for the status codes and resulting errors were largely copied and pasted so I tried to make a framework to reduce that for the stuff I was writing. It does make a lot more sense to refactor everything later when everything is using a standardized way of handling errors like you commented before. I'm mainly a C# dev and garbage collection is usually an afterthought for me because of that, so thanks for ironing that out. Looks good to me 👍

Copy link
Collaborator

@Felanbird Felanbird left a comment

Choose a reason for hiding this comment

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

I'm not 100% on the fact that we are deprecating the command very early, but /chatters usage is probably more common among stable users, so we could take another look at this around Feb when the deprecation of all other commands kicks in.

@pajlada pajlada changed the title Migrate /chatters commands to use helix api Migrate /chatters commands to use Helix api Nov 1, 2022
@pajlada pajlada enabled auto-merge (squash) November 1, 2022 21:20
@pajlada pajlada merged commit 495f3ed into Chatterino:master Nov 1, 2022
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.

Migrate the Viewer List and the /chatters command to Helix API
3 participants