Compare commits
2 Commits
5ea7b438f5
...
008852c781
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
008852c781 | ||
|
|
d19f03d412 |
@@ -55,6 +55,12 @@ public class PostModerationExecutorService {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!approved) {
|
||||
postRepository.updateStatus(postId, PostStatus.REJECTED);
|
||||
log.info("Пост {} отклонён модерацией.", post.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
postRepository.updateStatus(postId, PostStatus.ACTIVE);
|
||||
log.info("Пост {} прошёл модерацию.", post.getId());
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.krylov.refound.entity.Post;
|
||||
import com.krylov.refound.enums.PostStatus;
|
||||
import com.krylov.refound.repository.FavoriteRepository;
|
||||
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.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -20,6 +22,8 @@ public class SchedulerService {
|
||||
private final PostRepository postRepository;
|
||||
private final FavoriteRepository favoriteRepository;
|
||||
private final PostModerationExecutorService postModerationExecutorService;
|
||||
private final PostCacheService postCacheService;
|
||||
private final MapCacheService mapCacheService;
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
if (!closedPosts.isEmpty() || !oldPosts.isEmpty()) {
|
||||
// Иначе удалённые посты висят в ленте и на карте до TTL кэша
|
||||
postCacheService.invalidatePosts();
|
||||
mapCacheService.clearMapMarkersCache();
|
||||
}
|
||||
|
||||
log.info("Scheduled cleanup completed successfully");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user