Restore the actual purpose of the code.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 19 Oct 2013 14:43:58 +0000 (16:43 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:29 +0000 (22:25 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java

index 63bf181..612398d 100644 (file)
@@ -616,11 +616,12 @@ public class Core extends AbstractService implements SoneProvider {
                        return null;
                }
                synchronized (sones) {
-                       final Sone sone = database.newSoneBuilder().by(identity.getId()).build(Optional.<SoneCreated>absent());
-                       if (sone.isLocal()) {
-                               return sone;
+                       Optional<Sone> existingSone = database.getSone(identity.getId());
+                       if (existingSone.isPresent() && existingSone.get().isLocal()) {
+                               return existingSone.get();
                        }
-                       boolean newSone = sone.getRequestUri() == null;
+                       boolean newSone = !existingSone.isPresent();
+                       final Sone sone = newSone ? database.newSoneBuilder().by(identity.getId()).build(Optional.<SoneCreated>absent()) : existingSone.get();
                        sone.setRequestUri(SoneUri.create(identity.getRequestUri()));
                        sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
                        if (newSone) {