mirror of
https://github.com/ramsayleung/rspotify.git
synced 2026-04-25 23:45:52 +03:00
[GH-ISSUE #132] Partial model object with fields query parameter #45
Labels
No labels
Stale
bug
discussion
enhancement
good first issue
good first issue
help wanted
pull-request
question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/rspotify#45
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ghost on GitHub (Oct 7, 2020).
Original GitHub issue: https://github.com/ramsayleung/rspotify/issues/132
Some Spotify endpoints, especially the ones returning a paging object, allow to specify the fields that we want to fetch.
For example,
Get a Playlist's Itemshas afieldsquery parameter that allow selection of fields, but we can't use it since it would raise an error when trying to deserialize the fields that are not specify :This behaviour makes the
fieldsparameter useless and forces to fetch data even if we don't need it. Solutions to that would be :#[serde(default)]on existing model object fieldsOptionon existing model object fieldsPartialTrack, that implement either1.or2.and make endpoints that use afieldsquery parameter return such aPartialobject instead of aFullorSimplifiedone.I think
3.would be the most reasonable solution, moreover it might be possible to implement it using a macro.@mendelsimon commented on GitHub (Aug 29, 2022):
I've run into this as well, and I agree with @Sydpy's conclusion.
@kangalio commented on GitHub (May 23, 2023):
I wonder if the additional complexity is even worth it. I feel like that Spotify API feature is mainly useful for dynamically typed languages, where specifying the fields you're working with is a quick low-effort change to reduce load. But in Rust, you'd have to use a different type, and then
.unwrap()all the fields you're working with - a significant amount of friction. To keep rspotify's API simple, maybe this feature shouldn't be implemented?@mendelsimon commented on GitHub (May 29, 2023):
I think there's enough value in this feature for it to not be abandoned. At the time of my previous comment, I had hacked together a proof of concept to test if it actually made a difference for my workflow (fetching the IDs of all tracks in a playlist), and the speed difference was significant.
@kangalio commented on GitHub (May 29, 2023):
That is interesting. Can you share the benchmarking code?
@mendelsimon commented on GitHub (May 29, 2023):
Unfortunately, it was just a quick hack job to informally test it and was not saved. If I recall correctly, it was pretty much copy-pasting the relevant structs and functions required to make it work, tweaking the struct to only save the ID (I don't recall if I made the other fields Optional or removed them entirely), and passing the
fieldsparameter to only fetch the ID.@dylif commented on GitHub (Oct 22, 2023):
I've just ran into this issue. Forgive me if I'm missing something here, but why is the
fieldsparameter provided if using it doesn't work?@sandersantema commented on GitHub (Jan 2, 2025):
I think a fallback where a raw
serde_json::Valueis returned would already be very nice. Such a solution would hopefully require the least amount of work to implement while still allowing for use of the fields functionality. The downside is that it would require some work on the side of the user of the library to handle the returned data, but even this does allow for a lot of flexibility.