Skip to content

Favorites management API changes#127

Open
darrell-k wants to merge 4 commits intoLMS-Community:masterfrom
darrell-k:favoritesManagement
Open

Favorites management API changes#127
darrell-k wants to merge 4 commits intoLMS-Community:masterfrom
darrell-k:favoritesManagement

Conversation

@darrell-k
Copy link
Copy Markdown
Contributor

Replace favorite/getUserFavorites with favorite/getUserFavoriteIds or favorite/status when retrieving the status of favorites. It's a lot less data.

In QobuzGetTracks and QobuzArtist use favorite/status to return a simple boolean.

In QobuzManageFavorites use favorite/getUserFavoriteIds because although it's more data to return than favorite/status, it avoids having to call the status API 3 times (for albums, tracks and artists).

The new API results are cached for 60 seconds, like favorite/getUserFavorites, so extend the cache management in createFavorite and deleteFavorite.

Please give this a good going over.

…gement

Signed-off-by: darrell-k <darrell@darrell.org.uk>
Signed-off-by: darrell-k <darrell@darrell.org.uk>
@SamInPgh
Copy link
Copy Markdown
Contributor

Running with the changes now. Do you anticipate this having any affect on the OMLI import process? I haven't looked at the code yet but could imagine a possible conflict.

@darrell-k
Copy link
Copy Markdown
Contributor Author

There shouldn't be any effect on OMLI, but worth checking.

Comment thread API.pm Outdated
Comment on lines +441 to +445
$self->getUserFavorites(sub{}, 'refresh');
$self->getUserFavoriteIds(sub{}, 'refresh');
$self->getUserFavoriteStatus(sub{}, { type => 'album', item_id => $args->{album_ids} }, 'refresh') if $args->{album_ids};
$self->getUserFavoriteStatus(sub{}, { type => 'artist', item_id => $args->{artist_ids} }, 'refresh') if $args->{artist_ids};
$self->getUserFavoriteStatus(sub{}, { type => 'track', item_id => $args->{track_ids} }, 'refresh') if $args->{track_ids};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is doing more work than before. Is it worth it? Wouldn't the first call have all the information the subsequent two would get us?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We're just clearing caches here, after an add or delete favourite. Maybe we should do it within the add/delete api routines. At least we would know which of the 3 types to clear in the case of the status cache.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not only wiping caches, you're doing calls to eg. favorite/status, too, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, sorry I meant wipe/recreate cache. We could delay the recreation of the cache entry until it is requested again, so just do the clear at that stage.

Signed-off-by: darrell-k <darrell@darrell.org.uk>
@darrell-k
Copy link
Copy Markdown
Contributor Author

See new commit. I don't think it's worth refreshing the favorites caches when favourites change when they only last 60 seconds anyway, so we just delete them.

Comment thread API.pm Outdated

if ($params->{_wipecache}) {
$cache->remove($cacheKey);
if ( $params->{_wipecache} eq 'delete_cache_no_refresh' ) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As we are dealing with named parameters in $params, why not pass $params->{delete_cache_no_refresh} instead of doing a string comparison, rendering _wipecache ambiguous? At the very least I'd strongly recommend you replace the repeated use of the string literal with a constant. That way a typo would immediately cause the start to fail, rather than fail the comparison at run time, leading to unexpected behaviour.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See latest commit. I've changed the favorites APIs to use only named parameters. I've also allowed for callers to override any parameters defined in the individual APIs if they want to.

Do you like this approach? Should I extend it to all the APIs?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd use constants whenever there's static string literals to compare otherwise. If you know of other places where this happens I'd recommend you change that. I only commented on the changes in this PR...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll check for string literals.

What I was trying to say is that the APIs use a mixture of positional parameters and named parameters in a hash. I've changed this for the favorite* APIs so that named parameters are always used.

I was wondering if I should apply the same to the rest of the APIs?

Signed-off-by: darrell-k <darrell@darrell.org.uk>
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