From 5eccbebb663ee7c2098ce93a5aa3834376f8e566 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 25 Jan 2013 20:13:58 +0100 Subject: [PATCH] Avoid retaining multiple copies of elements. --- .../java/net/pterodactylus/sone/core/Core.java | 50 +++++----------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 901614e..d7b998e 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1109,18 +1109,16 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, List storedPosts = storedSone.getPosts(); synchronized (knownPosts) { for (Post post : sone.getPosts()) { - PostBuilder postBuilder = postBuilderFactory.newPostBuilder(); - postBuilder.copyPost(post).from(storedSone.getId()); - Post newPost = postBuilder.build().setKnown(knownPosts.contains(post.getId())); - if (!storedPosts.contains(newPost)) { - if (newPost.getTime() < getSoneFollowingTime(sone)) { - knownPosts.add(newPost.getId()); - newPost.setKnown(true); - } else if (!knownPosts.contains(newPost.getId())) { - eventBus.post(new NewPostFoundEvent(newPost)); + post.setKnown(knownPosts.contains(post.getId())); + if (!storedPosts.contains(post)) { + if (post.getTime() < getSoneFollowingTime(sone)) { + knownPosts.add(post.getId()); + post.setKnown(true); + } else if (!knownPosts.contains(post.getId())) { + eventBus.post(new NewPostFoundEvent(post)); } } - posts.put(newPost.getId(), newPost); + posts.put(post.getId(), post); } } } @@ -1165,36 +1163,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, } } } - synchronized (storedSone) { - if (!soneRescueMode || (sone.getTime() > storedSone.getTime())) { - storedSone.setTime(sone.getTime()); - } - storedSone.setClient(sone.getClient()); - storedSone.setProfile(sone.getProfile()); - if (soneRescueMode) { - for (Post post : sone.getPosts()) { - storedSone.addPost(post); - } - for (PostReply reply : sone.getReplies()) { - storedSone.addReply(reply); - } - for (String likedPostId : sone.getLikedPostIds()) { - storedSone.addLikedPostId(likedPostId); - } - for (String likedReplyId : sone.getLikedReplyIds()) { - storedSone.addLikedReplyId(likedReplyId); - } - for (Album album : sone.getAlbums()) { - storedSone.addAlbum(album); - } - } else { - storedSone.setPosts(sone.getPosts()); - storedSone.setReplies(sone.getReplies()); - storedSone.setLikePostIds(sone.getLikedPostIds()); - storedSone.setLikeReplyIds(sone.getLikedReplyIds()); - storedSone.setAlbums(sone.getAlbums()); - } - storedSone.setLatestEdition(sone.getLatestEdition()); + synchronized (sones) { + sones.put(sone.getId(), sone); } } } -- 2.7.4