Optimize User#seenOnServer to save on database updates
This commit is contained in:
parent
26c399fc8e
commit
7126dde94a
@ -147,7 +147,11 @@ public final class User {
|
||||
}
|
||||
}
|
||||
|
||||
public void seenOnServer(Server server) {
|
||||
public boolean seenOnServer(Server server) {
|
||||
if (online && server.getId().equals(this.lastSeenOn)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.lastSeenOn = server.getId();
|
||||
|
||||
if (!online) {
|
||||
@ -155,6 +159,7 @@ public final class User {
|
||||
}
|
||||
|
||||
this.online = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void leftServer() {
|
||||
@ -175,6 +180,7 @@ public final class User {
|
||||
}
|
||||
|
||||
this.aliases.put(username, new Date());
|
||||
APIv3.getDatastore().save(this);
|
||||
}
|
||||
|
||||
public void setPassword(String input) {
|
||||
|
@ -50,10 +50,13 @@ public final class POSTServerHeartbeat implements Route {
|
||||
if (user == null) {
|
||||
// Will be saved by the save command a few lines down.
|
||||
user = new User(uuid, username);
|
||||
APIv3.getDatastore().save(user);
|
||||
}
|
||||
|
||||
user.seenOnServer(actorServer);
|
||||
APIv3.getDatastore().save(user);
|
||||
// Only save if needed
|
||||
if (user.seenOnServer(actorServer)) {
|
||||
APIv3.getDatastore().save(user);
|
||||
}
|
||||
|
||||
onlinePlayers.add(user.getId());
|
||||
playersResponse.put(user.getId().toString(), user.getLoginInfo(actorServer));
|
||||
|
@ -45,7 +45,6 @@ public final class POSTUserLogin implements Route {
|
||||
|
||||
user.getIPLogEntry(userIp).used();
|
||||
user.updateUsername(username);
|
||||
APIv3.getDatastore().save(user);
|
||||
return user.getLoginInfo(actorServer);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user