Skip to content

Commit

Permalink
Use slow queries for flexible attributes in aunique (fix #2678, close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jcassette committed Nov 11, 2021
1 parent 3b53181 commit b67c25a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,9 @@ def tmpl_aunique(self, keys=None, disam=None, bracket=None):
subqueries = []
for key in keys:
value = album.get(key, '')
subqueries.append(dbcore.MatchQuery(key, value))
# Use slow queries for flexible attributes.
fast = key in album.item_keys
subqueries.append(dbcore.MatchQuery(key, value, fast))
albums = self.lib.albums(dbcore.AndQuery(subqueries))

# If there's only one album to matching these details, then do
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Bug fixes:

* :doc:`/plugins/export`: Fix duplicated output.

* :doc:`/dev/library`: Use slow queries for flexible attributes in aunique.
:bug:`2678` :bug:`3553`

1.5.0 (August 19, 2021)
-----------------------

Expand Down
10 changes: 10 additions & 0 deletions test/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,16 @@ def test_remove_brackets(self):
self._setf('foo%aunique{albumartist album,year,}/$title')
self._assert_dest(b'/base/foo 2001/the title', self.i1)

def test_key_flexible_attribute(self):
album1 = self.lib.get_album(self.i1)
album1.flex = 'flex1'
album2 = self.lib.get_album(self.i2)
album2.flex = 'flex2'
album1.store()
album2.store()
self._setf('foo%aunique{albumartist album flex,year}/$title')
self._assert_dest(b'/base/foo/the title', self.i1)


class PluginDestinationTest(_common.TestCase):
def setUp(self):
Expand Down

0 comments on commit b67c25a

Please sign in to comment.