Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add a flag to the synapse_review_recent_signups script to ignore and filter appservice users. #11675

Merged
merged 2 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11675.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds a flag to the `synapse_review_recent_signups` script to ignore and filter appservice users.
lukasdenk marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 11 additions & 2 deletions synapse/_scripts/review_recent_signups.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class UserInfo:
ips: List[str] = attr.Factory(list)


def get_recent_users(txn: LoggingTransaction, since_ms: int) -> List[UserInfo]:
def get_recent_users(
txn: LoggingTransaction, since_ms: int, exclude_app_service: bool
) -> List[UserInfo]:
"""Fetches recently registered users and some info on them."""

sql = """
Expand All @@ -56,6 +58,9 @@ def get_recent_users(txn: LoggingTransaction, since_ms: int) -> List[UserInfo]:
AND deactivated = 0
"""

if exclude_app_service:
sql += "\n AND appservice_id IS NOT NULL"
lukasdenk marked this conversation as resolved.
Show resolved Hide resolved

txn.execute(sql, (since_ms / 1000,))

user_infos = [UserInfo(user_id, creation_ts) for user_id, creation_ts in txn]
Expand Down Expand Up @@ -121,6 +126,9 @@ def main() -> None:
action="store_true",
help="Only print user IDs that match.",
)
parser.add_argument(
"-a", "--exclude-app-service", help="Exclude appservice users.", default=False
lukasdenk marked this conversation as resolved.
Show resolved Hide resolved
)

config = ReviewConfig()

Expand All @@ -133,6 +141,7 @@ def main() -> None:

since_ms = time.time() * 1000 - Config.parse_duration(config_args.since)
exclude_users_with_email = config_args.exclude_emails
exclude_users_with_appservice = config_args.exclude_app_service
include_context = not config_args.only_users

for database_config in config.database.databases:
Expand All @@ -143,7 +152,7 @@ def main() -> None:

with make_conn(database_config, engine, "review_recent_signups") as db_conn:
# This generates a type of Cursor, not LoggingTransaction.
user_infos = get_recent_users(db_conn.cursor(), since_ms) # type: ignore[arg-type]
user_infos = get_recent_users(db_conn.cursor(), since_ms, exclude_users_with_appservice) # type: ignore[arg-type]

for user_info in user_infos:
if exclude_users_with_email and user_info.emails:
Expand Down