[AB-12] fixing not ignoring ignored starboard posts in starstats

fixes #12
This commit is contained in:
Sheldan
2022-06-20 23:50:39 +02:00
parent 5ad3e30cc1
commit 74cee39f1a
5 changed files with 10 additions and 5 deletions

View File

@@ -30,7 +30,8 @@ public interface StarboardPostReactionRepository extends JpaRepository<Starboard
@Query(value = "SELECT COUNT(*) \n" +
"FROM starboard_post_reaction r \n" +
"INNER JOIN starboard_post p ON p.id = r.post_id\n" +
"WHERE p.server_id = :serverId\n"
"WHERE p.server_id = :serverId\n" +
"AND p.ignored = false"
, nativeQuery = true)
Integer getReactionCountByServer(Long serverId);

View File

@@ -18,7 +18,7 @@ public interface StarboardPostRepository extends JpaRepository<StarboardPost, Lo
List<StarboardPost> findByServer_Id(Long serverId);
Long countByServer_Id(Long serverId);
Long countByServer_IdAndIgnoredIsFalse(Long serverId);
@Query(value = "SELECT p.id, COUNT(*) AS starCount \n" +
" FROM starboard_post p \n" +

View File

@@ -218,7 +218,11 @@ public class StarboardServiceBean implements StarboardService {
allFutures.addAll(topStarReceiverFutures);
return FutureUtils.toSingleFuture(allFutures).thenApply(aVoid -> {
List<StarboardPost> starboardPosts = starboardPostManagementService.retrieveTopPosts(serverId, count);
List<StarStatsPost> starStatsPosts = starboardPosts.stream().map(this::fromStarboardPost).sorted(Comparator.comparingLong(StarStatsPost::getStarCount).reversed()).collect(Collectors.toList());
List<StarStatsPost> starStatsPosts = starboardPosts
.stream()
.map(this::fromStarboardPost)
.sorted(Comparator.comparingLong(StarStatsPost::getStarCount).reversed())
.collect(Collectors.toList());
Long postCount = starboardPostManagementService.getPostCount(serverId);
Integer reactionCount = starboardPostReactorManagementService.getStarCount(serverId);
List<String> emotes = new ArrayList<>();

View File

@@ -85,7 +85,7 @@ public class StarboardPostManagementServiceBean implements StarboardPostManageme
@Override
public Long getPostCount(Long serverId) {
return repository.countByServer_Id(serverId);
return repository.countByServer_IdAndIgnoredIsFalse(serverId);
}
@Override

View File

@@ -206,7 +206,7 @@ public class StarboardPostManagementServiceBeanTest {
@Test
public void testRetrievePostCount() {
Long expectedCount = 2L;
when(repository.countByServer_Id(SERVER_ID)).thenReturn(expectedCount);
when(repository.countByServer_IdAndIgnoredIsFalse(SERVER_ID)).thenReturn(expectedCount);
Long retrievedPostCount = testUnit.getPostCount(SERVER_ID);
Assert.assertEquals(expectedCount, retrievedPostCount);
}