From a39a1801e425f56c6cb0c9885f3524abfecceb91 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Sat, 25 Jun 2016 19:02:07 -0400 Subject: [PATCH] Slightly optimize number of db queries used in POST /users/:id/leave --- .../frozenorb/apiv3/route/users/POSTUsersIdLeave.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdLeave.java b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdLeave.java index 8534205..a6cc287 100644 --- a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdLeave.java +++ b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdLeave.java @@ -26,10 +26,15 @@ public class POSTUsersIdLeave implements Handler { 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);