fix feed pagination order, moderation reject and cache invalidation
- getFeed: add id DESC as tie-breaker so posts with equal createdAt are not duplicated or lost between pages - moderation: AI verdict false now sets REJECTED instead of ACTIVE - nightly cleanup: invalidate feed and map caches after deleting posts Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -27,7 +27,9 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -92,6 +94,13 @@ public class PostService {
|
||||
|
||||
public Page<PostResponse> getFeed(String search, Pageable pageable) {
|
||||
|
||||
// Без уникального ключа в сортировке порядок постов с одинаковым createdAt
|
||||
// недетерминирован, и при LIMIT/OFFSET посты дублируются или пропадают между страницами
|
||||
if (pageable.getSort().getOrderFor("id") == null) {
|
||||
pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(),
|
||||
pageable.getSort().and(Sort.by(Sort.Direction.DESC, "id")));
|
||||
}
|
||||
|
||||
// Ключ содержит версию ленты, она читается до запроса в БД
|
||||
String cacheKey = postCacheKeyGenerator.feedKey(search, pageable);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user