Skip to content

Commit cd42152

Browse files
committed
cli: Filters for 'records list'
1 parent d2f9849 commit cd42152

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

bbblb/cli/recording.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,32 @@ async def recording(obj: ServiceRegistry):
2121

2222

2323
@recording.command("list")
24+
@click.option("--tenant", help="Filter by tenant")
25+
@click.option("--format", help="Filter by format")
2426
@async_command()
25-
async def _list(obj: ServiceRegistry):
27+
async def _list(obj: ServiceRegistry, tenant: str, format: str):
2628
"""List all recordings and their formats"""
2729
db = await obj.use(DBContext)
2830
async with db.session() as session, session.begin():
2931
stmt = (
3032
model.Recording.select()
31-
.options(
32-
sqlalchemy.orm.joinedload(model.Recording.tenant),
33-
sqlalchemy.orm.selectinload(model.Recording.formats),
34-
)
35-
.execution_options(yield_per=100)
33+
.join(model.Recording.tenant)
34+
.options(sqlalchemy.orm.contains_eager(model.Recording.tenant))
3635
)
36+
if tenant:
37+
stmt = stmt.where(model.Tenant.name == tenant)
38+
if format:
39+
stmt = stmt.where(
40+
model.Recording.formats.any(model.PlaybackFormat.format == format)
41+
)
3742
async for record in await session.stream_scalars(stmt):
43+
format_names = (
44+
[format]
45+
if format
46+
else [f.format for f in await record.awaitable_attrs.formats]
47+
)
3848
click.echo(
39-
f"{record.tenant.name} {record.record_id} {','.join(f.format for f in record.formats)}"
49+
f"{record.tenant.name} {record.record_id} {record.state} {','.join(format_names)}"
4050
)
4151

4252

docs/_click.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,16 @@ recording list
205205

206206
List all recordings and their formats
207207

208+
.. table:: Options
209+
:width: 100%
210+
211+
============= ================
212+
Option Help
213+
============= ================
214+
--tenant TEXT Filter by tenant
215+
--format TEXT Filter by format
216+
============= ================
217+
208218
recording delete
209219
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
210220

0 commit comments

Comments
 (0)