Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -47,6 +47,18 @@ public interface CommunityRepository extends JpaRepository<Community, Long> {
join fetch c.pin p
join fetch p.user
where c.communityType = :type
and (
:type not in (
issueissyu.backend.domain.community.enums.CommunityType.STORE,
issueissyu.backend.domain.community.enums.CommunityType.FESTIVAL
)
or exists (
select 1
from EventPin ep
where ep.pin = p
and :now between ep.eventStartTime and ep.eventEndTime
)
)
and exists (
select 1
from PinLocation pl
Expand All @@ -62,6 +74,7 @@ and exists (
""")
List<Community> findFeedByTypeAndRegion(
@Param("type") CommunityType type,
@Param("now") LocalDateTime now,
@Param("locationId") Long locationId,
@Param("cursorCreatedAt") LocalDateTime cursorCreatedAt,
@Param("cursorId") Long cursorId,
Expand All @@ -80,6 +93,18 @@ List<Community> findFeedByTypeAndRegion(
join fetch c.pin p
join fetch p.user
where c.communityType in :types
and (
c.communityType not in (
issueissyu.backend.domain.community.enums.CommunityType.STORE,
issueissyu.backend.domain.community.enums.CommunityType.FESTIVAL
)
or exists (
select 1
from EventPin ep
where ep.pin = p
and :now between ep.eventStartTime and ep.eventEndTime
)
)
and exists (
select 1
from PinLocation pl
Expand All @@ -95,6 +120,7 @@ and exists (
""")
List<Community> findFeedByTypesAndRegion(
@Param("types") Collection<CommunityType> types,
@Param("now") LocalDateTime now,
@Param("locationId") Long locationId,
@Param("cursorCreatedAt") LocalDateTime cursorCreatedAt,
@Param("cursorId") Long cursorId,
Expand Down Expand Up @@ -175,6 +201,18 @@ List<Community> findCardnewsFeedByTypesWithImages(
where (
(
c.communityType in :regionTypes
and (
c.communityType not in (
issueissyu.backend.domain.community.enums.CommunityType.STORE,
issueissyu.backend.domain.community.enums.CommunityType.FESTIVAL
)
or exists (
select 1
from EventPin ep
where ep.pin = p
and :now between ep.eventStartTime and ep.eventEndTime
)
)
and exists (
select 1
from PinLocation pl
Expand All @@ -194,6 +232,7 @@ and exists (
List<Community> findFeedByRegionOrGlobalTypes(
@Param("regionTypes") Collection<CommunityType> regionTypes,
@Param("globalTypes") Collection<CommunityType> globalTypes,
@Param("now") LocalDateTime now,
@Param("locationId") Long locationId,
@Param("cursorCreatedAt") LocalDateTime cursorCreatedAt,
@Param("cursorId") Long cursorId,
Expand Down Expand Up @@ -221,6 +260,18 @@ List<Community> findFeedByRegionOrGlobalTypes(
where (
(
c.communityType in :regionTypes
and (
c.communityType not in (
issueissyu.backend.domain.community.enums.CommunityType.STORE,
issueissyu.backend.domain.community.enums.CommunityType.FESTIVAL
)
or exists (
select 1
from EventPin ep
where ep.pin = p
and :now between ep.eventStartTime and ep.eventEndTime
)
)
and exists (
select 1
from PinLocation pl
Expand All @@ -241,6 +292,7 @@ and exists (
List<Community> findHotFeedByRegionOrGlobalTypes(
@Param("regionTypes") Collection<CommunityType> regionTypes,
@Param("globalTypes") Collection<CommunityType> globalTypes,
@Param("now") LocalDateTime now,
@Param("locationId") Long locationId,
@Param("since") LocalDateTime since,
@Param("cursorPopularity") Double cursorPopularity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ public class CommunityHotQueryServiceImpl implements CommunityHotQueryService {

@Override
public Optional<HotCommunityTarget> findTopHotInRegion(Long locationId) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime since = LocalDateTime.now().minusDays(HOT_DAYS);
Pageable limit = PageRequest.of(0, 1);

List<Community> communities = communityRepository.findHotFeedByRegionOrGlobalTypes(
REGION_BASED_FEED_TYPES,
GLOBAL_FEED_TYPES,
now,
locationId,
since,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,12 @@ public CommunityQueryService.CommunityDetailResult getCommunityDetail(

private List<Community> fetchCommunities(CommunityTab tab, Long locationId, CursorKey cursorKey) {
Pageable limit = PageRequest.of(0, sizeWithLookahead(cursorKey.requestSize()));
LocalDateTime now = LocalDateTime.now();

return switch (tab) {
case ISSUE -> communityRepository.findFeedByTypeAndRegion(
CommunityType.ISSUE,
now,
locationId,
cursorKey.createdAt(),
cursorKey.communityId(),
Expand All @@ -261,6 +263,7 @@ private List<Community> fetchCommunities(CommunityTab tab, Long locationId, Curs

case STORE -> communityRepository.findFeedByTypeAndRegion(
CommunityType.STORE,
now,
locationId,
cursorKey.createdAt(),
cursorKey.communityId(),
Expand All @@ -269,6 +272,7 @@ private List<Community> fetchCommunities(CommunityTab tab, Long locationId, Curs

case COMMUNICATION -> communityRepository.findFeedByTypeAndRegion(
CommunityType.COMMUNICATION,
now,
locationId,
cursorKey.createdAt(),
cursorKey.communityId(),
Expand All @@ -277,6 +281,7 @@ private List<Community> fetchCommunities(CommunityTab tab, Long locationId, Curs

case FESTIVAL -> communityRepository.findFeedByTypeAndRegion(
CommunityType.FESTIVAL,
now,
locationId,
cursorKey.createdAt(),
cursorKey.communityId(),
Expand Down Expand Up @@ -307,6 +312,7 @@ private List<Community> fetchCommunities(CommunityTab tab, Long locationId, Curs
case ALL -> communityRepository.findFeedByRegionOrGlobalTypes(
REGION_BASED_FEED_TYPES,
GLOBAL_FEED_TYPES,
now,
locationId,
cursorKey.createdAt(),
cursorKey.communityId(),
Expand Down Expand Up @@ -344,9 +350,11 @@ private boolean usesRegion(CommunityTab tab) {
private List<CommunityFeedItemResDTO> fetchStorePromotions(Long locationId, int storeSize) {
int resolvedSize = Math.min(Math.max(1, storeSize), MAX_STORE_SIZE);
Pageable limit = PageRequest.of(0, resolvedSize);
LocalDateTime now = LocalDateTime.now();

List<Community> communities = communityRepository.findFeedByTypeAndRegion(
CommunityType.STORE,
now,
locationId,
null,
null,
Expand All @@ -357,12 +365,14 @@ private List<CommunityFeedItemResDTO> fetchStorePromotions(Long locationId, int
}

private List<CommunityFeedItemResDTO> fetchHotPreviews(Long locationId) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime since = LocalDateTime.now().minusDays(HOT_DAYS);
Pageable limit = PageRequest.of(0, HOT_PREVIEW_SIZE);

return toFeedItems(communityRepository.findHotFeedByRegionOrGlobalTypes(
REGION_BASED_FEED_TYPES,
GLOBAL_FEED_TYPES,
now,
locationId,
since,
null,
Expand All @@ -374,9 +384,11 @@ private List<CommunityFeedItemResDTO> fetchHotPreviews(Long locationId) {
private CommunityCursorPageResDTO fetchRecentNews(Long locationId, String recentCursor, int recentSize) {
CursorKey cursorKey = CursorKey.parse(recentCursor, recentSize);
Pageable limit = PageRequest.of(0, sizeWithLookahead(cursorKey.requestSize()));
LocalDateTime now = LocalDateTime.now();

List<Community> communities = communityRepository.findFeedByTypesAndRegion(
REGION_BASED_FEED_TYPES,
now,
locationId,
cursorKey.createdAt(),
cursorKey.communityId(),
Expand Down Expand Up @@ -715,12 +727,14 @@ private String resolveWriterProfileUrl(CommunityType type, Pin pin) {

private CommunityCursorPageResDTO getHotFeed(Long locationId, String cursor, int size) {
HotCursorKey cursorKey = HotCursorKey.parse(cursor, size);
LocalDateTime now = LocalDateTime.now();
LocalDateTime since = LocalDateTime.now().minusDays(HOT_DAYS);
Pageable limit = PageRequest.of(0, sizeWithLookahead(size));

List<Community> communities = communityRepository.findHotFeedByRegionOrGlobalTypes(
REGION_BASED_FEED_TYPES,
GLOBAL_FEED_TYPES,
now,
locationId,
since,
cursorKey.popularity(),
Expand Down
Loading