perf(core): implement efficient bulk user deletion

Revamps the entire user deletion process to resolve critical performance bottlenecks that caused the web panel and database to freeze when removing multiple users.

- **Backend:** Core scripts (`kickuser.py`, `remove_user.py`) and the database layer are re-engineered to handle multiple users in a single, efficient batch operation using MongoDB's `delete_many`.
- **API:** A new `POST /api/v1/users/bulk-delete` endpoint is introduced for batch removals. The existing single-user `DELETE` endpoint is fixed to align with the new bulk logic.
- **Frontend:** The Users page now intelligently calls the bulk API when multiple users are selected, drastically improving UI responsiveness and reducing server load.
This commit is contained in:
ReturnFI
2025-09-13 16:15:41 +00:00
parent cb9804d71e
commit 949a12cea7
7 changed files with 90 additions and 46 deletions

View File

@ -36,15 +36,16 @@ def get_api_secret(config_path: str) -> str:
def main():
parser = argparse.ArgumentParser(
description="Kick a Hysteria2 user via the API.",
usage="%(prog)s <username>"
description="Kick one or more Hysteria2 users via the API.",
usage="%(prog)s <username1> [username2] ..."
)
parser.add_argument(
"username",
help="The username (Auth identity) to kick."
"usernames",
nargs='+',
help="The username(s) (Auth identity) to kick."
)
args = parser.parse_args()
username_to_kick = args.username
usernames_to_kick = args.usernames
try:
api_secret = get_api_secret(CONFIG_FILE)
@ -56,16 +57,14 @@ def main():
secret=api_secret
)
client.kick_clients([username_to_kick])
# print(f"User '{username_to_kick}' kicked successfully.")
client.kick_clients(usernames_to_kick)
sys.exit(0)
except (FileNotFoundError, KeyError, ValueError, json.JSONDecodeError) as e:
print(f"Configuration Error: {e}", file=sys.stderr)
sys.exit(1)
except Hysteria2Error as e:
print(f"API Error kicking user '{username_to_kick}': {e}", file=sys.stderr)
print(f"API Error kicking users: {e}", file=sys.stderr)
sys.exit(1)
except ConnectionError as e:
print(f"Connection Error: Could not connect to API at {API_BASE_URL}. Is it running? Details: {e}", file=sys.stderr)