From: David ‘Bombe’ Roden Date: Wed, 5 Nov 2014 20:01:44 +0000 (+0100) Subject: Only send events after the new Sone has been stored in the database. X-Git-Tag: 0.9-rc1^2~3^2~35 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a7bfeae4450d7d4aecc7499f894b90eea40480f0;p=Sone.git Only send events after the new Sone has been stored in the database. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 13076b8..97182c2 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -25,6 +25,7 @@ import static java.lang.String.format; import static java.util.logging.Level.WARNING; import static java.util.logging.Logger.getLogger; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -864,6 +865,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, logger.log(Level.FINE, String.format("Downloaded Sone %s is not newer than stored Sone %s.", sone, storedSone)); return; } + final List events = new ArrayList(); SoneChangeDetector soneChangeDetector = new SoneChangeDetector(storedSone.get()); soneChangeDetector.onNewPosts(new PostProcessor() { @Override @@ -871,14 +873,14 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, if (post.getTime() < getSoneFollowingTime(sone)) { post.setKnown(true); } else if (!post.isKnown()) { - eventBus.post(new NewPostFoundEvent(post)); + events.add(new NewPostFoundEvent(post)); } } }); soneChangeDetector.onRemovedPosts(new PostProcessor() { @Override public void processPost(Post post) { - eventBus.post(new PostRemovedEvent(post)); + events.add(new PostRemovedEvent(post)); } }); soneChangeDetector.onNewPostReplies(new PostReplyProcessor() { @@ -887,18 +889,21 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, if (postReply.getTime() < getSoneFollowingTime(sone)) { postReply.setKnown(true); } else if (!postReply.isKnown()) { - eventBus.post(new NewPostReplyFoundEvent(postReply)); + events.add(new NewPostReplyFoundEvent(postReply)); } } }); soneChangeDetector.onRemovedPostReplies(new PostReplyProcessor() { @Override public void processPostReply(PostReply postReply) { - eventBus.post(new PostReplyRemovedEvent(postReply)); + events.add(new PostReplyRemovedEvent(postReply)); } }); soneChangeDetector.detectChanges(sone); database.storeSone(sone); + for (Object event : events) { + eventBus.post(event); + } sone.setOptions(storedSone.get().getOptions()); sone.setKnown(storedSone.get().isKnown()); sone.setStatus((sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle);