Merge pull request #45 from SlimusMinus/fix-feed-pagination
All checks were successful
deploy-backend / deploy (push) Successful in 1m23s
All checks were successful
deploy-backend / deploy (push) Successful in 1m23s
fix feed pagination order, moderation reject and cache invalidation
This commit is contained in:
@@ -55,6 +55,12 @@ public class PostModerationExecutorService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!approved) {
|
||||||
|
postRepository.updateStatus(postId, PostStatus.REJECTED);
|
||||||
|
log.info("Пост {} отклонён модерацией.", post.getId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
postRepository.updateStatus(postId, PostStatus.ACTIVE);
|
postRepository.updateStatus(postId, PostStatus.ACTIVE);
|
||||||
log.info("Пост {} прошёл модерацию.", post.getId());
|
log.info("Пост {} прошёл модерацию.", post.getId());
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageImpl;
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -92,6 +94,13 @@ public class PostService {
|
|||||||
|
|
||||||
public Page<PostResponse> getFeed(String search, Pageable pageable) {
|
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);
|
String cacheKey = postCacheKeyGenerator.feedKey(search, pageable);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.krylov.refound.entity.Post;
|
|||||||
import com.krylov.refound.enums.PostStatus;
|
import com.krylov.refound.enums.PostStatus;
|
||||||
import com.krylov.refound.repository.FavoriteRepository;
|
import com.krylov.refound.repository.FavoriteRepository;
|
||||||
import com.krylov.refound.repository.PostRepository;
|
import com.krylov.refound.repository.PostRepository;
|
||||||
|
import com.krylov.refound.service.redis.MapCacheService;
|
||||||
|
import com.krylov.refound.service.redis.PostCacheService;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -20,6 +22,8 @@ public class SchedulerService {
|
|||||||
private final PostRepository postRepository;
|
private final PostRepository postRepository;
|
||||||
private final FavoriteRepository favoriteRepository;
|
private final FavoriteRepository favoriteRepository;
|
||||||
private final PostModerationExecutorService postModerationExecutorService;
|
private final PostModerationExecutorService postModerationExecutorService;
|
||||||
|
private final PostCacheService postCacheService;
|
||||||
|
private final MapCacheService mapCacheService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs every day at 00:01 to delete:
|
* Runs every day at 00:01 to delete:
|
||||||
@@ -55,6 +59,12 @@ public class SchedulerService {
|
|||||||
log.info("Deleted {} posts older than 6 months", oldPosts.size());
|
log.info("Deleted {} posts older than 6 months", oldPosts.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!closedPosts.isEmpty() || !oldPosts.isEmpty()) {
|
||||||
|
// Иначе удалённые посты висят в ленте и на карте до TTL кэша
|
||||||
|
postCacheService.invalidatePosts();
|
||||||
|
mapCacheService.clearMapMarkersCache();
|
||||||
|
}
|
||||||
|
|
||||||
log.info("Scheduled cleanup completed successfully");
|
log.info("Scheduled cleanup completed successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user