aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-02-22 02:14:18 +0300
committerGravatar Vitaly Takmazov2023-02-22 02:14:43 +0300
commit2c8032aa075e9aaa73746429b05546a48c7e007e (patch)
treeda1468c70625469a35918ce0a6361178933232a0 /src/main/java/com
parent64e6b703b7fa50a31dc0b73ec85230aa99c77bd5 (diff)
Fix memory issues when using Reaction
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/juick/model/Reaction.java13
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java3
2 files changed, 13 insertions, 3 deletions
diff --git a/src/main/java/com/juick/model/Reaction.java b/src/main/java/com/juick/model/Reaction.java
index 4b3501d4..3f666cf6 100644
--- a/src/main/java/com/juick/model/Reaction.java
+++ b/src/main/java/com/juick/model/Reaction.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2020, Juick
+ * Copyright (C) 2008-2023, Juick
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -20,6 +20,7 @@ package com.juick.model;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.io.Serializable;
+import java.util.Objects;
public class Reaction implements Serializable {
@@ -41,6 +42,16 @@ public class Reaction implements Serializable {
.append("count", count)
.build();
}
+ @Override
+ public boolean equals(Object o) {
+ return o == this ||
+ (o instanceof Reaction) && Objects.equals(id, ((Reaction) o).id);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id);
+ }
public String getDescription() {
return description;
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index b0e365f8..083524b1 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -845,8 +845,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
Reaction reaction = new Reaction(likeId);
reaction.setCount(count);
reaction.setDescription(description);
- results.computeIfAbsent(messageId, HashSet::new);
- results.get(messageId).add(reaction);
+ results.computeIfAbsent(messageId, HashSet::new).add(reaction);
}
return results;
});