X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneInserter.java;h=2c0a25270c5634e6a780397146a335d36fa5de62;hb=bd05cecc1f894778248305054800a8a9e2c63969;hp=e8c828cb640b3aa588344bfb212e0bf12f85f3c9;hpb=7615a45cbc702122ab8bfe8d6a5c4932b90c4427;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java index e8c828c..2c0a252 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneInserter.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneInserter.java @@ -88,7 +88,7 @@ public class SoneInserter extends AbstractService { * The Sone to insert */ public SoneInserter(Core core, FreenetInterface freenetInterface, Sone sone) { - super("Sone Inserter for “" + sone.getName() + "”"); + super("Sone Inserter for “" + sone.getName() + "”", false); this.core = core; this.freenetInterface = freenetInterface; this.sone = sone; @@ -104,28 +104,31 @@ public class SoneInserter extends AbstractService { @Override protected void serviceRun() { long modificationCounter = 0; - boolean restartNow = true; + long lastModificationTime = 0; while (!shouldStop()) { - if (!restartNow) { - logger.log(Level.FINEST, "Waiting 60 seconds before checking Sone “" + sone.getName() + "”."); - sleep(60 * 1000); - } - restartNow = false; + /* check every seconds. */ + sleep(1000); + InsertInformation insertInformation = null; synchronized (sone) { - modificationCounter = sone.getModificationCounter(); - if (modificationCounter > 0) { - sone.setTime(System.currentTimeMillis()); + if (sone.getModificationCounter() > modificationCounter) { + modificationCounter = sone.getModificationCounter(); + lastModificationTime = System.currentTimeMillis(); + sone.setTime(lastModificationTime); + logger.log(Level.FINE, "Sone %s has been modified, waiting 60 seconds before inserting.", new Object[] { sone.getName() }); + } + if ((lastModificationTime > 0) && ((System.currentTimeMillis() - lastModificationTime) > (60 * 1000))) { insertInformation = new InsertInformation(sone); } } + if (insertInformation != null) { logger.log(Level.INFO, "Inserting Sone “%s”…", new Object[] { sone.getName() }); boolean success = false; try { core.setSoneStatus(sone, SoneStatus.inserting); - FreenetURI finalUri = freenetInterface.insertDirectory(insertInformation.getInsertUri().setKeyType("USK").setDocName("Sone-" + sone.getName()).setSuggestedEdition(0), insertInformation.generateManifestEntries(), "index.html"); + FreenetURI finalUri = freenetInterface.insertDirectory(insertInformation.getInsertUri().setKeyType("USK").setSuggestedEdition(0), insertInformation.generateManifestEntries(), "index.html"); sone.updateUris(finalUri); success = true; logger.log(Level.INFO, "Inserted Sone “%s” at %s.", new Object[] { sone.getName(), finalUri }); @@ -144,9 +147,8 @@ public class SoneInserter extends AbstractService { if (sone.getModificationCounter() == modificationCounter) { logger.log(Level.FINE, "Sone “%s” was not modified further, resetting counter…", new Object[] { sone }); sone.setModificationCounter(0); - } else { - logger.log(Level.FINE, "Sone “%s” was modified since the insert started, starting another insert…", new Object[] { sone }); - restartNow = true; + modificationCounter = 0; + lastModificationTime = 0; } } } @@ -181,8 +183,9 @@ public class SoneInserter extends AbstractService { soneProperties.put("profile", sone.getProfile()); soneProperties.put("posts", new ArrayList(sone.getPosts())); soneProperties.put("replies", new HashSet(sone.getReplies())); - soneProperties.put("friends", new HashSet(sone.getFriends())); soneProperties.put("blockedSoneIds", new HashSet(sone.getBlockedSoneIds())); + soneProperties.put("likedPostIds", new HashSet(sone.getLikedPostIds())); + soneProperties.put("likeReplyIds", new HashSet(sone.getLikedReplyIds())); } //