-
Notifications
You must be signed in to change notification settings - Fork 438
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: add MojangUtil.queueUsernameForUUID #444
base: dev
Are you sure you want to change the base?
Conversation
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
val username = name.lowercase() | ||
usernameQueue.emit(username to System.currentTimeMillis()) | ||
|
||
return uuidFlow.first { it.first == username }.second |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if 2 queue the same username what will happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should still emit. Only StateFlow
will disregard repeated consecutive elements.
val usernames = ArrayDeque<Pair<String, Long>>(10) | ||
usernameQueue.collect { name -> | ||
usernames.add(name) | ||
if (usernames.size >= 10 || usernames.isNotEmpty() && System.currentTimeMillis() - usernames.first().second >= 3000L) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this condition good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're trying to create what is effectively a bucket ratelimiter, there are probably better ways to handle this (see Levelhead). Otherwise, you'd probably want your usernameQueue
flow to have a replay cache (and buffer) of 10 so you can access queued values more than once.
Also, It'd probably be nice to add qualifying parenthesis around the second condition because it's not very straightforward from a glance.
usernameQueue.collect { name -> | ||
usernames.add(name) | ||
if (usernames.size >= 10 || usernames.isNotEmpty() && System.currentTimeMillis() - usernames.first().second >= 3000L) { | ||
getUUIDsFromUsernames(usernames.map { it.first }).forEach { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be better to directly emit the API response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks fine but a few concerns.
val username = name.lowercase() | ||
usernameQueue.emit(username to System.currentTimeMillis()) | ||
|
||
return uuidFlow.first { it.first == username }.second |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should still emit. Only StateFlow
will disregard repeated consecutive elements.
val usernames = ArrayDeque<Pair<String, Long>>(10) | ||
usernameQueue.collect { name -> | ||
usernames.add(name) | ||
if (usernames.size >= 10 || usernames.isNotEmpty() && System.currentTimeMillis() - usernames.first().second >= 3000L) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're trying to create what is effectively a bucket ratelimiter, there are probably better ways to handle this (see Levelhead). Otherwise, you'd probably want your usernameQueue
flow to have a replay cache (and buffer) of 10 so you can access queued values more than once.
Also, It'd probably be nice to add qualifying parenthesis around the second condition because it's not very straightforward from a glance.
suspend fun queueUsernameForUUID(name: String): UUID? { | ||
val username = name.lowercase() | ||
usernameQueue.emit(username to System.currentTimeMillis()) | ||
|
||
return uuidFlow.first { it.first == username }.second | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any guarantee that the username will be resolved? Afaict you need to pray someone else calls MojangUtil#getUsernameFromUUID
.
142a4c5
to
fdb45e9
Compare
55917b7
to
9056242
Compare
Queue usernames for UUID lookup and wait until completed
Run usernames in batch by waiting for at least 10? or max 3 seconds