Skip to content
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

MBS-13943: Lookup multiple URLs at once with the API #3483

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mwiencek
Copy link
Member

Problem

https://tickets.metabrainz.org/browse/MBS-13943

Solution

This just allows specifying multiple resource query parameters on the existing /ws/2/url endpoint. It returns a url-list in that case, rather than a single URL.

Testing

Added some automated test cases.

@kellnerd
Copy link
Contributor

Wow, that was fast! Now I feel dumb for not having already requested that a few years ago 😂

I don't recall any precedent for a query parameter which can be specified multiple times.
All existing parameters which support multiple values (inc, status and type) join them using a + or |, but this is not possible for "free-form" (URL) values.

@mwiencek
Copy link
Member Author

mwiencek commented Feb 20, 2025

I don't recall any precedent for a query parameter which can be specified multiple times.
All existing parameters which support multiple values (inc, status and type) join them using a + or |, but this is not possible for "free-form" (URL) values.

Yeah, there's no precedent for it, but the only way I can see to allow joining multiple of them in the same field would be to require users to double-encode spaces in the URL, which is...weird. Specifying them as separate parameters seems a bit more elegant.

The URL "browse" endpoint is already very weird, since it's not actually a browse endpoint. It meets neither of the criteria that all other browse endpoints share:

  • Browsing is done via a different (linked) entity ID
  • Browsing returns multiple entities

Specifying multiple resource parameters now meets the second criteria, but not the first; it's still just a direct URL lookup.

kellnerd added a commit to kellnerd/musicbrainz-ts that referenced this pull request Feb 20, 2025
Multiple `resource` query parameters (up to 100) can now be specified:
metabrainz/musicbrainz-server#3483

Also rename the method since this closer to a "lookup" than to a
"browse" request, although https://musicbrainz.org/doc/MusicBrainz_API
currently lists it as a "browse" request.
kellnerd added a commit to kellnerd/musicbrainz-ts that referenced this pull request Feb 20, 2025
Multiple `resource` query parameters (up to 100) can now be specified:
metabrainz/musicbrainz-server#3483

Also rename the method since this closer to a "lookup" than to a
"browse" request, although https://musicbrainz.org/doc/MusicBrainz_API
currently lists it as a "browse" request.
@kellnerd
Copy link
Contributor

I agree, the /ws/2/url endpoint is (or was before this PR at least) much more similar to a lookup endpoint. Funnily enough, it accepts the paging parameters limit and offset of a browse request, where they (currently?) don't have any effect. This won't change with this PR, as the number of results only depends on the number of (distinct?) resource query parameters, right?

P.S. Might be a bit soon, but I've already added support for this in my MB client 😁
Since I'm still doing 0.x versions, I can also afford to rename the method from browseUrl to lookupByUrl and am now wondering whether it should accept BrowseOptions or only LookupOptions.

Relationships that are equal according to all other criteria currently in
`Data::Relationship::_load` (including target entity name) are now sorted by
target entity ID and relationship ID.

This should fix some random test failures that occur depending on which system
they are executed on.
There's no reason that this should return a list containing one URL.

I kept a bare `return;` at the end so that it still works properly in list
context.
This just allows specifying multiple `resource` query parameters on the
existing /ws/2/url endpoint. It returns a `url-list` in that case, rather than
a single URL.
Direct lookups of URLs via the `resource` parameter cannot be considered a
"browse" query, as they don't find URLs linked via another entity type. The
`url.url` column has a UNIQUE index; it's just as much of a lookup as using the
MBID.

This commit doesn't change any behavior of the /ws/2/url endpoint, but
clarifies the code a bit more. Note that tests for `resource` lookups were
already contained in files named LookupURL.pm.
@mwiencek
Copy link
Member Author

mwiencek commented Feb 21, 2025

I agree, the /ws/2/url endpoint is (or was before this PR at least) much more similar to a lookup endpoint. Funnily enough, it accepts the paging parameters limit and offset of a browse request, where they (currently?) don't have any effect. This won't change with this PR, as the number of results only depends on the number of (distinct?) resource query parameters, right?

Right, limit and offset will still be unused. It's just performing a single batch lookup with no paging. And in general you can add &random=crap to any WS call without triggering an error, so I'm not surprised they were accepted (i.e. ignored) before, but maybe we should be stricter about that for parameters with known uses.

P.S. Might be a bit soon, but I've already added support for this in my MB client 😁

I'll echo what you said earlier: That was fast! Nice work!

Since I'm still doing 0.x versions, I can also afford to rename the method from browseUrl to lookupByUrl and am now wondering whether it should accept BrowseOptions or only LookupOptions.

Only inc from LookupOptions is valid. And only *-rels inc parameters, plus artist-credits if recording-rels, release-rels, or release-group-rels is specified, are valid.

I also pushed a commit here to get rid of some "browse" language from the endpoint in MBS.

Copy link
Member

@reosarevok reosarevok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good, but it seems https://wiki.musicbrainz.org/MusicBrainz_API needs to be updated too to document the new options ;) (url is listed there as being browsed by resource too)

Comment on lines +322 to +324
if (defined $row) {
return $self->_new_from_row($row);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to be annoying, but if find_by_url always returns one result, shouldn't it also be renamed to get_by_url? 😝 find_by_ methods seem to mostly return lists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants