From: David ‘Bombe’ Roden Date: Mon, 2 Jun 2014 04:43:10 +0000 (+0200) Subject: Use a multimap to store posts with recipienets. X-Git-Tag: 0.9-rc1^2~3^2~256 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e641b6984bf4d67fb842d7a858e8521f2b34155f;p=Sone.git Use a multimap to store posts with recipienets. --- diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 238c533..d7e9f58 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -84,7 +84,7 @@ public class MemoryDatabase extends AbstractService implements Database { private final Multimap sonePosts = HashMultimap.create(); /** All posts by their recipient. */ - private final Map> recipientPosts = new HashMap>(); + private final Multimap recipientPosts = HashMultimap.create(); /** Whether posts are known. */ private final Set knownPosts = new HashSet(); @@ -627,26 +627,12 @@ public class MemoryDatabase extends AbstractService implements Database { * @return All posts */ private Collection getPostsTo(String recipientId) { - Collection posts = null; lock.readLock().lock(); try { - posts = recipientPosts.get(recipientId); + return recipientPosts.get(recipientId); } finally { lock.readLock().unlock(); } - if (posts != null) { - return posts; - } - - posts = new HashSet(); - lock.writeLock().lock(); - try { - recipientPosts.put(recipientId, posts); - } finally { - lock.writeLock().unlock(); - } - - return posts; } /** Loads the known posts. */