-
Notifications
You must be signed in to change notification settings - Fork 138
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
Add latest
function to Metadata
#110
Conversation
Hi @JasonLG1979, I commented on your linked issue, but I'll copy and paste the parts relevant to this PR below.
Unfortunately, as-is this PR will expose a footgun in the form of a pseudo memory leak, as well as potentially weird behaviour in the latter case mentioned in the comment above. I'm open to making life easier for your use-case though. Perhaps we could modify the behaviour of the function to clear all but the latest revision. Then rename the function to |
Ok. That sounds like it complicates things. A person could for example assume that rev2 contains all of rev1 + whatever changed from rev1 to rev2 and that doesn't always seem to be the case. If the revs can be implemented as basically diffs then we may need to change our implementation at librespot and just fast forwarding to the latest without considering prev revs is a mistake. |
I think for librespot it's perfectly okay to assume the last revision is the latest and complete. I wouldn't recommend any changes other than properly popping queue. That's because Spotify just serves you a single song per file. Even in the case of something like a chained OGG physical stream where new revisions would be expected, the diffing use-case would be very application specific. I just don't want Symphonia to assume how a user should consume their metadata. |
In my PR to librespot I do: let latest_metadata = if metadata.is_latest() {
metadata.current()?
} else {
loop {
match metadata.pop() {
// Advance to the latest metadata revision.
Some(_discarded_revision) => continue,
// None means we hit the latest.
None => break metadata.current()?,
}
}
}; Is that not correct?
That's all Greek to me. I will take your word for it.
That's completely understandable. |
I'm not a fan of pub fn fastforward_to_latest(&self) {
let rev_len = self.revisions.len();
if rev_len > 1 {
self.revisions = self.revisions.split_off(rev_len - 1);
}
} or pub fn fastforward_to_latest(&self) {
loop {
if self.pop().is_none() {
break;
}
}
} |
Hi @JasonLG1979,
This looks correct. Since that code is in the context of a larger function you could probably simplify it with something like this until the helper function in Symphonia gets published: while metadata.pop().is_some() {}
let latest_metadata = metadata.current()?; For this PR I like your second option. My only concern is that fast-forward has other meanings in media so I'd probably prefer just calling it
Thanks! |
We are basically of one mind. Since my last comment I've changed my code in the librespot PR to basically the same as loop {
if metadata.pop().is_none() {
break;
}
}
Skip to last it is then. |
Two more questions: Should 1: pub fn skip_to_latest(&self) -> Option<&MetadataRevision> {
loop {
if self.pop().is_none() {
break;
}
}
self.revisions.pop_front()
} 2: pub fn skip_to_latest(&self) -> Option<&MetadataRevision> {
while self.pop().is_some() {}
self.revisions.pop_front()
} 3: pub fn skip_to_latest(&self) {
loop {
if self.pop().is_none() {
break;
}
}
} 4: pub fn skip_to_latest(&self) {
while self.pop().is_some() {}
} |
Options 1 and 2 are actually incorrect because it should be impossible to empty the underlying queue ( But your suggestion is a good one. How about: pub fn skip_to_latest(&self) -> Option<&MetadataRevision> {
loop {
if self.pop().is_none() {
break;
}
}
self.current()
} Then a user could do: let latest_metadata = metadata.skip_to_latest(); |
ae18356
to
d755bdf
Compare
Yep, that was a typo. My bad. How's that look? |
Aside from the missing |
* Skips to, and gets an immutable reference to the latest, and therefore newest, revision of the metadata.
d755bdf
to
06288e0
Compare
More typos 🤦♂️ Done. |
We're all merged now. Thanks for your work on this! |
Thank you!!! |
Removes the need to pop though the revisions via a loop when all you want is the latest.
As mentioned in librespot-org/librespot#967