Skip to content

Commit

Permalink
Fix the count query in extract_users
Browse files Browse the repository at this point in the history
Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard committed Mar 28, 2024
1 parent 601440e commit b5812fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
23 changes: 10 additions & 13 deletions datanommer.commands/datanommer/commands/extract_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,22 @@ def main(config_path, topic, category, force_schema):
elif category:
query = query.where(m.Message.category == category)

query = (
query.join(
m.users_assoc_table,
and_(
m.Message.id == m.users_assoc_table.c.msg_id,
m.Message.timestamp == m.users_assoc_table.c.msg_timestamp,
),
isouter=True,
)
.where(m.users_assoc_table.c.msg_id.is_(None))
.order_by(m.Message.timestamp)
)
query = query.join(
m.users_assoc_table,
and_(
m.Message.id == m.users_assoc_table.c.msg_id,
m.Message.timestamp == m.users_assoc_table.c.msg_timestamp,
),
isouter=True,
).where(m.users_assoc_table.c.msg_id.is_(None))

total = m.session.scalar(query.with_only_columns(func.count(m.Message.id)))
if not total:
click.echo("No messages matched.")
return

click.echo(f"Considering {total} messages")
query = query.order_by(m.Message.timestamp)
click.echo(f"Considering {total} message{'s' if total > 1 else ''}")

for message in m.session.scalars(query):
headers = message.headers
Expand Down
2 changes: 1 addition & 1 deletion datanommer.commands/tests/test_extract_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ def test_extract_users_no_users(datanommer_models, mock_config, mock_init):
sa.select(sa.func.count(m.users_assoc_table.c.msg_id))
)
assert users_count == 0
assert result.output == ""
assert result.output == "Considering 1 message\n"

0 comments on commit b5812fc

Please sign in to comment.