Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication: Fix an issue with duplicated posts on course wide search #9819

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.tum.cit.aet.artemis.communication.repository;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;

import jakarta.persistence.EntityManager;
Expand Down Expand Up @@ -50,6 +52,8 @@ public Page<Long> findPostIdsWithSpecification(Specification<Post> specification
query.setMaxResults(pageable.getPageSize());

List<Long> postIds = query.getResultList();
// removes all duplicates from the answer posts
List<Long> uniquePostIds = new ArrayList<>(new LinkedHashSet<>(postIds));
MaximilianAnzinger marked this conversation as resolved.
Show resolved Hide resolved

// Count query
CriteriaQuery<Long> countQuery = builder.createQuery(Long.class);
Expand All @@ -66,6 +70,6 @@ public Page<Long> findPostIdsWithSpecification(Specification<Post> specification
Long countResult = entityManager.createQuery(countQuery).getSingleResult();
long count = countResult != null ? countResult : 0L;

return new PageImpl<>(postIds, pageable, count);
return new PageImpl<>(uniquePostIds, pageable, count);
}
}
Loading