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

Make %aunique work with -f/--format options. #3043

Merged
merged 3 commits into from
Sep 27, 2018
Merged

Make %aunique work with -f/--format options. #3043

merged 3 commits into from
Sep 27, 2018

Conversation

djl
Copy link
Member

@djl djl commented Sep 27, 2018

This should fix #3042. Let's see if Travis gives the thumbs up...

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you!! Here’s one small comment.

beets/library.py Outdated
@@ -1395,6 +1395,8 @@ def get_album(self, item_or_id):
"""
if isinstance(item_or_id, int):
album_id = item_or_id
elif isinstance(item_or_id, Album):
album_id = item_or_id.id
Copy link
Member

Choose a reason for hiding this comment

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

If this function can now accept Album objects, maybe we should update the docstring to reflect that? (Also, I don’t quite see where the call is that makes this change necessary—maybe that call should be rewritten to just use the Album object it already has instead of going to the database to get another identical copy?)

Copy link
Member Author

Choose a reason for hiding this comment

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

The call to lib.get_album() comes from tmpl_aunique where self.item can be either an Item or an Album.

I couldn't think of a clean way of refactoring that method. I suppose lib.get_album(), if given an Album, could just return the same object. That would prevent hitting the database twice.

Copy link
Member

Choose a reason for hiding this comment

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

How about using lib.get_album(album_id)? In your improved version of tmpl_aunique, we now have an album_id variable already. That won't prevent hitting the database twice, but it will avoid expanding the responsibilities of get_album.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! Pushed a new commit.

@sampsyo
Copy link
Member

sampsyo commented Sep 27, 2018

Awesome. Looks perfect. 🎉 🚀 🐭

@sampsyo sampsyo merged commit 54cf6d4 into master Sep 27, 2018
@arcresu arcresu deleted the aunique-format branch April 24, 2019 05:03
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.

%aunique fails when listing albums
2 participants