projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
403b51b
)
Move retrieval of post likes from Core to Post.
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Tue, 5 Nov 2013 19:20:45 +0000
(20:20 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:53 +0000
(22:25 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/data/Post.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/database/PostDatabase.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/fcp/LikePostCommand.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/template/PostAccessor.java
patch
|
blob
|
history
src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/sone/core/Core.java
b/src/main/java/net/pterodactylus/sone/core/Core.java
index
3ca5271
..
0caf03f
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/core/Core.java
+++ b/
src/main/java/net/pterodactylus/sone/core/Core.java
@@
-413,23
+413,6
@@
public class Core extends AbstractService implements SoneProvider {
}
/**
}
/**
- * Returns all Sones that have liked the given post.
- *
- * @param post
- * The post to get the liking Sones for
- * @return The Sones that like the given post
- */
- public Set<Sone> getLikes(Post post) {
- Set<Sone> sones = new HashSet<Sone>();
- for (Sone sone : getSones()) {
- if (sone.getLikedPostIds().contains(post.getId())) {
- sones.add(sone);
- }
- }
- return sones;
- }
-
- /**
* Returns all Sones that have liked the given reply.
*
* @param reply
* Returns all Sones that have liked the given reply.
*
* @param reply
diff --git
a/src/main/java/net/pterodactylus/sone/data/Post.java
b/src/main/java/net/pterodactylus/sone/data/Post.java
index
269c2e4
..
474f9d1
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/Post.java
+++ b/
src/main/java/net/pterodactylus/sone/data/Post.java
@@
-20,6
+20,7
@@
package net.pterodactylus.sone.data;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.Set;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Function;
import com.google.common.base.Optional;
@@
-127,6
+128,8
@@
public interface Post extends Identified {
public void like(Sone localSone);
public void unlike(Sone localSone);
public void like(Sone localSone);
public void unlike(Sone localSone);
+ Set<Sone> getLikes();
+
List<PostReply> getReplies();
}
List<PostReply> getReplies();
}
diff --git
a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
index
fa21e7a
..
587add9
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
+++ b/
src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java
@@
-20,6
+20,7
@@
package net.pterodactylus.sone.data.impl;
import static com.google.common.collect.FluentIterable.from;
import java.util.List;
import static com.google.common.collect.FluentIterable.from;
import java.util.List;
+import java.util.Set;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
@@
-138,6
+139,11
@@
public class DefaultPost implements Post {
}
@Override
}
@Override
+ public Set<Sone> getLikes() {
+ return database.getLikes(this);
+ }
+
+ @Override
public List<PostReply> getReplies() {
return from(database.getReplies(getId())).toSortedList(Reply.TIME_COMPARATOR);
}
public List<PostReply> getReplies() {
return from(database.getReplies(getId())).toSortedList(Reply.TIME_COMPARATOR);
}
diff --git
a/src/main/java/net/pterodactylus/sone/database/PostDatabase.java
b/src/main/java/net/pterodactylus/sone/database/PostDatabase.java
index
8bdca6c
..
a25f245
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/database/PostDatabase.java
+++ b/
src/main/java/net/pterodactylus/sone/database/PostDatabase.java
@@
-18,6
+18,7
@@
package net.pterodactylus.sone.database;
import java.util.Collection;
package net.pterodactylus.sone.database;
import java.util.Collection;
+import java.util.Set;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
@@
-101,5
+102,6
@@
public interface PostDatabase {
void likePost(Post post, Sone localSone);
void unlikePost(Post post, Sone localSone);
void likePost(Post post, Sone localSone);
void unlikePost(Post post, Sone localSone);
+ Set<Sone> getLikes(Post post);
}
}
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
c73513d
..
975b8ab
100644
(file)
--- 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,8
@@
public class MemoryDatabase extends AbstractService implements Database {
/** All posts by their Sones. */
private final Multimap<String, Post> sonePosts = HashMultimap.create();
/** All posts by their Sones. */
private final Multimap<String, Post> sonePosts = HashMultimap.create();
- private final SetMultimap<String, String> likedPosts = HashMultimap.create();
+ private final SetMultimap<String, String> likedPostsBySone = HashMultimap.create();
+ private final SetMultimap<String, String> postLikingSones = HashMultimap.create();
/** All posts by their recipient. */
private final Multimap<String, Post> recipientPosts = HashMultimap.create();
/** All posts by their recipient. */
private final Multimap<String, Post> recipientPosts = HashMultimap.create();
@@
-290,7
+291,8
@@
public class MemoryDatabase extends AbstractService implements Database {
public void likePost(Post post, Sone localSone) {
lock.writeLock().lock();
try {
public void likePost(Post post, Sone localSone) {
lock.writeLock().lock();
try {
- likedPosts.put(localSone.getId(), post.getId());
+ likedPostsBySone.put(localSone.getId(), post.getId());
+ postLikingSones.put(post.getId(), localSone.getId());
} finally {
lock.writeLock().unlock();
}
} finally {
lock.writeLock().unlock();
}
@@
-300,12
+302,23
@@
public class MemoryDatabase extends AbstractService implements Database {
public void unlikePost(Post post, Sone localSone) {
lock.writeLock().lock();
try {
public void unlikePost(Post post, Sone localSone) {
lock.writeLock().lock();
try {
- likedPosts.remove(localSone.getId(), post.getId());
+ likedPostsBySone.remove(localSone.getId(), post.getId());
+ postLikingSones.remove(post.getId(), localSone.getId());
} finally {
lock.writeLock().unlock();
}
}
} finally {
lock.writeLock().unlock();
}
}
+ @Override
+ public Set<Sone> getLikes(Post post) {
+ lock.readLock().lock();
+ try {
+ return from(postLikingSones.get(post.getId())).transform(getSone()).transformAndConcat(this.<Sone>unwrap()).toSet();
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
//
// POSTSTORE METHODS
//
//
// POSTSTORE METHODS
//
@@
-837,4
+850,13
@@
public class MemoryDatabase extends AbstractService implements Database {
};
}
};
}
+ private static <T> Function<Optional<T>, Iterable<T>> unwrap() {
+ return new Function<Optional<T>, Iterable<T>>() {
+ @Override
+ public Iterable<T> apply(Optional<T> input) {
+ return (input == null) ? Collections.<T>emptyList() : input.asSet();
+ }
+ };
+ }
+
}
}
diff --git
a/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
b/src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
index
62d6a53
..
baa3129
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
+++ b/
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
@@
-289,7
+289,7
@@
public abstract class AbstractSoneCommand extends AbstractCommand {
}
postBuilder.put(prefix + "Time", post.getTime());
postBuilder.put(prefix + "Text", encodeString(post.getText()));
}
postBuilder.put(prefix + "Time", post.getTime());
postBuilder.put(prefix + "Text", encodeString(post.getText()));
- postBuilder.put(encodeLikes(
core.getLikes(post
), prefix + "Likes."));
+ postBuilder.put(encodeLikes(
post.getLikes(
), prefix + "Likes."));
return postBuilder;
}
return postBuilder;
}
diff --git
a/src/main/java/net/pterodactylus/sone/fcp/LikePostCommand.java
b/src/main/java/net/pterodactylus/sone/fcp/LikePostCommand.java
index
d2acb4a
..
4a88ce1
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/fcp/LikePostCommand.java
+++ b/
src/main/java/net/pterodactylus/sone/fcp/LikePostCommand.java
@@
-47,7
+47,7
@@
public class LikePostCommand extends AbstractSoneCommand {
Post post = getPost(parameters, "Post");
Sone sone = getMandatoryLocalSone(parameters, "Sone");
post.like(sone);
Post post = getPost(parameters, "Post");
Sone sone = getMandatoryLocalSone(parameters, "Sone");
post.like(sone);
- return new Response("PostLiked", new SimpleFieldSetBuilder().put("LikeCount",
getCore().getLikes(post
).size()).get());
+ return new Response("PostLiked", new SimpleFieldSetBuilder().put("LikeCount",
post.getLikes(
).size()).get());
}
}
}
}
diff --git
a/src/main/java/net/pterodactylus/sone/template/PostAccessor.java
b/src/main/java/net/pterodactylus/sone/template/PostAccessor.java
index
74c3d9f
..
c3f9de3
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/template/PostAccessor.java
+++ b/
src/main/java/net/pterodactylus/sone/template/PostAccessor.java
@@
-56,7
+56,7
@@
public class PostAccessor extends ReflectionAccessor {
if ("replies".equals(member)) {
return from(post.getReplies()).filter(Reply.FUTURE_REPLY_FILTER).toList();
} else if (member.equals("likes")) {
if ("replies".equals(member)) {
return from(post.getReplies()).filter(Reply.FUTURE_REPLY_FILTER).toList();
} else if (member.equals("likes")) {
- return
core.getLikes(post
);
+ return
post.getLikes(
);
} else if (member.equals("liked")) {
Sone currentSone = (Sone) templateContext.get("currentSone");
return (currentSone != null) && (currentSone.isLikedPostId(post.getId()));
} else if (member.equals("liked")) {
Sone currentSone = (Sone) templateContext.get("currentSone");
return (currentSone != null) && (currentSone.isLikedPostId(post.getId()));
diff --git
a/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java
b/src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java
index
4838a4e
..
058b142
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java
+++ b/
src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java
@@
-68,7
+68,7
@@
public class GetLikesAjaxPage extends JsonPage {
if (!post.isPresent()) {
return createErrorJsonObject("invalid-post-id");
}
if (!post.isPresent()) {
return createErrorJsonObject("invalid-post-id");
}
- Set<Sone> sones =
webInterface.getCore().getLikes(post.get()
);
+ Set<Sone> sones =
post.get().getLikes(
);
return createSuccessJsonObject().put("likes", sones.size()).put("sones", getSones(sones));
} else if ("reply".equals(type)) {
Optional<PostReply> reply = webInterface.getCore().getDatabase().getPostReply(id);
return createSuccessJsonObject().put("likes", sones.size()).put("sones", getSones(sones));
} else if ("reply".equals(type)) {
Optional<PostReply> reply = webInterface.getCore().getDatabase().getPostReply(id);