-
Notifications
You must be signed in to change notification settings - Fork 83
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
Change attachment InputStream to ChannelProvider #682
Change attachment InputStream to ChannelProvider #682
Conversation
da6977d
to
dac0337
Compare
right, this is a binary incompatible change |
You need to run |
Also remove full eager consuming of stream/channel when building request and just pass it directly. Remove a test regarding closing a stream after building the request, which is no longer significant. Closes kordlib#674
dac0337
to
854d49e
Compare
rest/src/main/kotlin/builder/message/create/MessageCreateBuilder.kt
Outdated
Show resolved
Hide resolved
rest/src/main/kotlin/builder/message/create/MessageCreateBuilder.kt
Outdated
Show resolved
Hide resolved
rest/src/main/kotlin/builder/message/create/MessageCreateBuilder.kt
Outdated
Show resolved
Hide resolved
rest/src/main/kotlin/builder/message/create/MessageCreateBuilder.kt
Outdated
Show resolved
Hide resolved
rest/src/main/kotlin/builder/message/modify/MessageModifyBuilder.kt
Outdated
Show resolved
Hide resolved
rest/src/main/kotlin/builder/message/modify/MessageModifyBuilder.kt
Outdated
Show resolved
Hide resolved
rest/src/main/kotlin/builder/message/modify/MessageModifyBuilder.kt
Outdated
Show resolved
Hide resolved
Another thought I had was to use (and btw sorry for requesting so many changes) |
Another thought I had was to use `ChannelProvider` directly as inputs for
the functions (instead of `ByteReadChannel`). This would mean the channel
wouldn't even have to be opened until executing the request. What is your
thought on this?
Yeah I thought about it when first implementing this change, but ended up
deciding that taking a read channel directly would be more convenient most of
the time. However, also accepting a channel provider would make this even
more versatile (which was kinda the whole point to this change). Perhaps I
could change the internals once again to `ChannelProvider` and write
overloads for those `addFile` methods and such that can accept both providers
and channels directly (which would be wrapped in simple providers)?
(and btw sorry for requesting so many changes)
No problem at all! In fact, I appreciate the detailed reviewing :)
|
Sounds good 👍 |
Cool!
I'll be out for most of today, so I'll either submit this later in the
evening or tomorrow.
|
So yeah, now it complains that Also, would like suggestions regarding that test. |
just slap |
I think we actually need to mock a request so that the channel gets consumed. Take a look at |
Right... 🤦 |
The channel never seems to get consumed in the mock request, which is odd. I'll push what I have, maybe I'm overlooking something obvious again 🙃 |
Let me check this out and take a look at it. |
Sure thing! Thanks a lot :)
|
I PRed the fix here: Tmpod#1 |
I found another problem with using Here we retry a request when we got a rate limit. This means we call This is actually also a problem with
Of course rate limit on the exact request that uploads a file might not happen very often, but when it does, I'm pretty sure it'll fail. |
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.
Suggestions for updates to deprecation messages and replacements based on this comment: #682 (comment)
rest/src/main/kotlin/builder/message/create/MessageCreateBuilder.kt
Outdated
Show resolved
Hide resolved
rest/src/main/kotlin/builder/message/create/MessageCreateBuilder.kt
Outdated
Show resolved
Hide resolved
rest/src/main/kotlin/builder/message/modify/MessageModifyBuilder.kt
Outdated
Show resolved
Hide resolved
rest/src/main/kotlin/builder/message/modify/MessageModifyBuilder.kt
Outdated
Show resolved
Hide resolved
Mmm, well spotted.
This is actually also a problem with `InputStream` that we had before, but now that we refactor this, what should we do?
- add the convenience functions that take `ByteReadChannel` (like it is rn)
- add the convenience functions that take `ByteReadChannel` but add a warning in the docs
- don't have these convenience functions (I would actually prefer this)
I agree with the last one yeah. We can still have `Path` overloads that make providers like
`ChannelProvider { path.readChannel() }`
but prevent people from making the mistake of providing a single channel that can potentially cause issues.
*Edit: ugh, why doesn't github process markdown from email replies*
|
Fix test and update ktor version
ad66008
to
d576efa
Compare
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.
Looks good overall, just one last question left
rest/src/main/kotlin/builder/message/modify/MessageModifyBuilder.kt
Outdated
Show resolved
Hide resolved
d576efa
to
7026ad9
Compare
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.
I've committed my final touches here.
Could you update title and description of the PR (we no longer use ByteReadChannel
and the test wasn't removed)? Then we would be good to go. Thanks for your efforts :)
- consistent `contentProvider` name - optimize imports - add @Suppress KDoc tags
48351b2
to
8722751
Compare
Perfect!
Yep, good point hehe Thank you for your excellent reviewing! Helped me get back into Kotlin again :3 |
Also remove full eager consuming of stream/channel when building request and
just pass it directly.
Closes #674 (discussed in this Discord topic as well)