strager / First

GNU General Public License v3.0
3 stars 2 forks source link

User name cache table #7

Closed strager closed 1 year ago

strager commented 1 year ago

This table is needed in many places. For example, after we pull data from PointsDb, we need to map viewer user IDs to display names.

If we want pretty URLs like /stream/strager, we also need the inverse operation: user name to ID. (Note: user name might differ from display name. We should use user names for IDs, but display names for other stuff.)

I'm imagining an interface like this:

# Calls Twitch's /helix/users endpoint if the data is missing from the database.
# https://dev.twitch.tv/docs/api/reference/#get-users
def get_display_name_from_id(self, id: UserId) -> str: ...

# Not needed right now:
# Twitch's /helix/users endpoint allows multiple IDs. We can leverage this fact to improve performance of batch queries:
def get_display_name_from_id_batch(self, ids: typing.List[UserId]) -> typing.List[str]: ...

# Not needed right now:
# Calls Twitch's /helix/users endpoint if the data is missing from the database.
# https://dev.twitch.tv/docs/api/reference/#get-users
def get_user_id_from_user_name(self, user_name: str) -> UserId: ...

# Update the cache if we happen to receive data from some Twitch API (such as a redemption notification).
def set_user_info(self, user_id: UserId, user_name: typing.Optional[str], display_name: typing.Optional[str]): ...
mate-amargo commented 1 year ago

Done in commits b9038ae, e05a450, 178860f. minus the pretty URLs, @strager do we want to assemble the url using the user's display_name (user_name) or the user's login (user_login)? I'm not sure if we would have uniqueness issues. But anyway, maybe we'll do that part after the MVP is done, I guess we're ok with using ugly urls for now.

strager commented 1 year ago

Pretty URLs are not necessary for MVP.