Slightly optimize number of db queries used in POST /users/:id/leave

This commit is contained in:
Colin McDonald 2016-06-25 19:02:07 -04:00
parent 439f92f596
commit a39a1801e4

View File

@ -26,10 +26,15 @@ public class POSTUsersIdLeave implements Handler<RoutingContext> {
User.findById(ctx.request().getParam("id"), ((user, error) -> {
if (error != null) {
ErrorUtils.respondInternalError(ctx, error);
} else if (user == null) {
return;
}
if (user == null) {
ErrorUtils.respondNotFound(ctx, "User", ctx.request().getParam("id"));
} else {
user.leftServer(actorServer);
return;
}
if (user.leftServer(actorServer)) {
user.save((ignored, error2) -> {
if (error2 != null) {
ErrorUtils.respondInternalError(ctx, error2);