Query items whose albums match a sub-query

I’m wondering what it would take to list items whose albums match a specified album query, particularly for commands which expect an item query, not an album one. I’m specifically thinking about inline album fields, which can’t be accessed from the item in a query.

I.e. beet ls some_item_field:1 album_query:‘is_incomplete:0’

I’d imagine it’d be trivial to implement a quick and dirty, but slow, version of this in a plugin by parsing that album query string, doing the item query, iterating over it, and checking if the album_query matches the item’s album, or flipping it around, first matching the album, then checking if its items match the item query, but I’m wondering if there’d be a faster method given beets internal api, which I don’t yet know well.

Hi! There’s actually a pretty cool and somewhat complete pull request putting something similar into practice:

Take a look. The current status is that it seems to come at a nontrivial performance penalty, as you suspected.