From 4bd86d3eb17c985d6b128e594b0c1d6d33dd742a Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 7 Oct 2026 15:23:48 -0600 Subject: [PATCH] Count Channels with any of the Tags in the Other search estimate The Other tab lists Channels with any of the selected Tags, but its estimate only counted Channels with the first Tag, so the two disagreed when several Tags were selected. Co-Authored-By: Claude Opus 5.5 --- wrolpi/common.py | 4 ++-- wrolpi/test/test_root_api.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/wrolpi/common.py b/wrolpi/common.py index c6ea4af2..321478f5 100644 --- a/wrolpi/common.py +++ b/wrolpi/common.py @@ -2885,11 +2885,11 @@ async def search_other_estimates(session: Session, tag_names: List[str], search_ repo_count=repo_count, ) - # TODO handle multiple tags + # Matches `search_channels`: Channels with any of the Tags. channel_count = session.query(func.count(Channel.id)) \ .join(Collection, Collection.id == Channel.collection_id) \ .join(Tag, Tag.id == Collection.tag_id) \ - .filter(Tag.name == tag_names[0]) \ + .filter(Tag.name.in_(tag_names)) \ .scalar() others = dict( diff --git a/wrolpi/test/test_root_api.py b/wrolpi/test/test_root_api.py index 055e7364..a8163666 100644 --- a/wrolpi/test/test_root_api.py +++ b/wrolpi/test/test_root_api.py @@ -1016,6 +1016,18 @@ async def test_search_other_estimates(async_client, test_session, channel_factor assert response.status_code == HTTPStatus.OK assert response.json['others']['channel_count'] == 1, 'Only one Channel is tagged.' + # The estimate counts the Channels the search lists: those with any of the Tags. + tag2 = await tag_factory() + channel_factory(tag_name=tag2.name) + test_session.commit() + body = dict(tag_names=[tag.name, tag2.name]) + request, response = await async_client.post('/api/search_other_estimates', json=body) + assert response.status_code == HTTPStatus.OK + estimate = response.json['others']['channel_count'] + request, response = await async_client.post('/api/videos/channels/search', json=body) + assert response.status_code == HTTPStatus.OK + assert estimate == len(response.json['channels']) == 2 + @pytest.mark.asyncio async def test_mutating_request_survives_concurrent_writer(async_client, test_session, test_downloader,