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

@ -407,11 +407,26 @@
confirmButtonText: "Yes, delete them!",
}).then((result) => {
if (!result.isConfirmed) return;
const urlTemplate = "{{ url_for('remove_user_api', username='U') }}";
const promises = selectedUsers.map(user => $.ajax({ url: urlTemplate.replace('U', user), method: "DELETE" }));
Promise.all(promises)
.then(() => Swal.fire("Success!", "Selected users deleted.", "success").then(() => location.reload()))
.catch(() => Swal.fire("Error!", "An error occurred while deleting users.", "error"));
if (selectedUsers.length > 1) {
const bulkUrl = "{{ url_for('bulk_remove_users_api') }}";
$.ajax({
url: bulkUrl,
method: "POST",
contentType: "application/json",
data: JSON.stringify({ usernames: selectedUsers })
})
.done(() => Swal.fire("Success!", "Selected users have been deleted.", "success").then(() => location.reload()))
.fail((err) => Swal.fire("Error!", err.responseJSON?.detail || "An error occurred while deleting users.", "error"));
} else {
const singleUrl = "{{ url_for('remove_user_api', username='U') }}".replace('U', selectedUsers[0]);
$.ajax({
url: singleUrl,
method: "DELETE"
})
.done(() => Swal.fire("Success!", "The user has been deleted.", "success").then(() => location.reload()))
.fail((err) => Swal.fire("Error!", err.responseJSON?.detail || "An error occurred while deleting the user.", "error"));
}
});
});