Skip to content

Commit 4b07e0c

Browse files
authored
[DDING-000] 전체 동아리 대상 피드 조회 쿼리 수정 (#349)
1 parent 407c415 commit 4b07e0c

File tree

20 files changed

+344
-378
lines changed

20 files changed

+344
-378
lines changed

src/main/java/ddingdong/ddingdongBE/common/config/AsyncConfig.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,23 @@
1010
@EnableAsync
1111
public class AsyncConfig {
1212

13+
@Bean
14+
public Executor generalAsyncExecutor() {
15+
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
16+
executor.setCorePoolSize(5);
17+
executor.setMaxPoolSize(10);
18+
executor.setQueueCapacity(100);
19+
executor.setThreadNamePrefix("Async-");
20+
executor.initialize();
21+
return executor;
22+
}
23+
1324
@Bean
1425
public Executor emailAsyncExecutor() {
1526
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
1627
executor.setCorePoolSize(10);
1728
executor.setMaxPoolSize(10);
18-
executor.setQueueCapacity(500);
29+
executor.setQueueCapacity(5000);
1930
executor.setThreadNamePrefix("EmailAsync-");
2031
executor.initialize();
2132
return executor;

src/main/java/ddingdong/ddingdongBE/domain/feed/api/FeedApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ClubFeedPageResponse getFeedPageByClub(
3535
content = @Content(schema = @Schema(implementation = NewestFeedPerClubPageResponse.class)))
3636
@ResponseStatus(HttpStatus.OK)
3737
@GetMapping("/feeds")
38-
NewestFeedPerClubPageResponse getNewestFeedPerClub(
38+
NewestFeedPerClubPageResponse getAllFeedPage(
3939
@RequestParam(value = "size", defaultValue = "9") int size,
4040
@RequestParam(value = "currentCursorId", defaultValue = "-1") Long currentCursorId
4141
);

src/main/java/ddingdong/ddingdongBE/domain/feed/controller/FeedController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public ClubFeedPageResponse getFeedPageByClub(
2828
}
2929

3030
@Override
31-
public NewestFeedPerClubPageResponse getNewestFeedPerClub(
31+
public NewestFeedPerClubPageResponse getAllFeedPage(
3232
int size,
3333
Long currentCursorId
3434
) {
35-
NewestFeedPerClubPageQuery newestFeedPerClubPageQuery = facadeFeedService.getNewestFeedPerClubPage(size, currentCursorId);
35+
NewestFeedPerClubPageQuery newestFeedPerClubPageQuery = facadeFeedService.getAllFeedPage(size, currentCursorId);
3636
return NewestFeedPerClubPageResponse.from(newestFeedPerClubPageQuery);
3737
}
3838

src/main/java/ddingdong/ddingdongBE/domain/feed/repository/FeedRepository.java

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,23 @@ Slice<Feed> findPageByClubIdOrderById(
4040

4141
@Query(value = """
4242
select * from feed f
43-
where f.id in
44-
(select max(id)
45-
from feed
46-
where deleted_at is null
47-
and (
48-
f.feed_type != 'VIDEO'
49-
or exists (
50-
select 1
51-
from (
52-
select id
53-
from file_meta_data
54-
where entity_id = f.id
55-
and domain_type = 'FEED_VIDEO'
56-
) filtered_fm
57-
join vod_processing_job vpj
58-
on filtered_fm.id = vpj.file_meta_data_id
59-
where vpj.convert_job_status = 'COMPLETE'
60-
)
61-
)
62-
GROUP BY club_id)
63-
and (:currentCursorId = -1 or id < :currentCursorId)
64-
ORDER BY id DESC
65-
limit :size
66-
""",
67-
nativeQuery = true)
68-
Slice<Feed> findNewestPerClubPage(
43+
where f.deleted_at is null
44+
and (
45+
f.feed_type != 'VIDEO'
46+
or exists (
47+
select 1
48+
from file_meta_data fm
49+
join vod_processing_job vpj on fm.id = vpj.file_meta_data_id
50+
where fm.entity_id = f.id
51+
and fm.domain_type = 'FEED_VIDEO'
52+
and vpj.convert_job_status = 'COMPLETE'
53+
)
54+
)
55+
and (:currentCursorId = -1 or f.id < :currentCursorId)
56+
ORDER BY f.id DESC
57+
limit :size
58+
""", nativeQuery = true)
59+
Slice<Feed> getAllFeedPage(
6960
@Param("size") int size,
7061
@Param("currentCursorId") Long currentCursorId
7162
);

src/main/java/ddingdong/ddingdongBE/domain/feed/service/FacadeFeedService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public ClubFeedPageQuery getFeedPageByClub(Long clubId, int size, Long currentCu
3636
return ClubFeedPageQuery.of(feedListQueries, pagingQuery);
3737
}
3838

39-
public NewestFeedPerClubPageQuery getNewestFeedPerClubPage(int size, Long currentCursorId) {
40-
Slice<Feed> feedPage = feedService.getNewestFeedPerClubPage(size, currentCursorId);
39+
public NewestFeedPerClubPageQuery getAllFeedPage(int size, Long currentCursorId) {
40+
Slice<Feed> feedPage = feedService.getAllFeedPage(size, currentCursorId);
4141
if (feedPage == null) {
4242
return NewestFeedPerClubPageQuery.createEmpty();
4343
}

src/main/java/ddingdong/ddingdongBE/domain/feed/service/FeedService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public interface FeedService {
88

99
Slice<Feed> getFeedPageByClubId(Long clubId, int size, Long currentCursorId);
1010

11-
Slice<Feed> getNewestFeedPerClubPage(int size, Long currentCursorId);
11+
Slice<Feed> getAllFeedPage(int size, Long currentCursorId);
1212

1313
Feed getById(Long feedId);
1414

src/main/java/ddingdong/ddingdongBE/domain/feed/service/GeneralFeedService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public Slice<Feed> getFeedPageByClubId(Long clubId, int size, Long currentCursor
2727
}
2828

2929
@Override
30-
public Slice<Feed> getNewestFeedPerClubPage(int size, Long currentCursorId) {
31-
Slice<Feed> feedPages = feedRepository.findNewestPerClubPage(size + 1, currentCursorId);
30+
public Slice<Feed> getAllFeedPage(int size, Long currentCursorId) {
31+
Slice<Feed> feedPages = feedRepository.getAllFeedPage(size + 1, currentCursorId);
3232
return buildSlice(feedPages, size);
3333
}
3434

src/main/java/ddingdong/ddingdongBE/domain/form/service/event/SendFormResultEmailEvent.java renamed to src/main/java/ddingdong/ddingdongBE/domain/form/entity/FormResultSendingEmailInfo.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package ddingdong.ddingdongBE.domain.form.service.event;
1+
package ddingdong.ddingdongBE.domain.form.entity;
22

33
import ddingdong.ddingdongBE.email.entity.EmailContent;
44

5-
public record SendFormResultEmailEvent(
5+
public record FormResultSendingEmailInfo(
66
Long emailSendHistoryId,
77
String destinationEmail,
88
String destinationName,
9-
EmailContent emailContent) {
9+
EmailContent emailContent
10+
) {
1011
}

src/main/java/ddingdong/ddingdongBE/domain/form/infrastructure/SesFormResultEmailSender.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ddingdong.ddingdongBE.domain.form.infrastructure;
22

3+
import ddingdong.ddingdongBE.domain.form.entity.FormResultSendingEmailInfo;
34
import ddingdong.ddingdongBE.domain.form.service.FormResultEmailSender;
45
import ddingdong.ddingdongBE.email.entity.EmailContent;
56
import ddingdong.ddingdongBE.email.infrastructure.SesEmailSender;
@@ -22,12 +23,16 @@ public class SesFormResultEmailSender implements FormResultEmailSender {
2223
private final SesEmailSender sesEmailSender;
2324

2425
@Override
25-
public void sendResult(String destinationEmail, String destinationName, Long emailHistoryId, EmailContent emailContent) {
26-
SendEmailRequest sendEmailRequest = createSendEmailRequest(destinationEmail, destinationName, emailContent);
27-
sesEmailSender.sendResult(sendEmailRequest, emailHistoryId);
26+
public void sendResult(FormResultSendingEmailInfo info) {
27+
SendEmailRequest sendEmailRequest = createSendEmailRequest(
28+
info.destinationEmail(),
29+
info.destinationName(),
30+
info.emailContent()
31+
);
32+
sesEmailSender.sendResult(sendEmailRequest, info.emailSendHistoryId());
2833
}
2934

30-
private SendEmailRequest createSendEmailRequest( String destinationEmail, String destinationName, EmailContent emailContent) {
35+
private SendEmailRequest createSendEmailRequest(String destinationEmail, String destinationName, EmailContent emailContent) {
3136
return SendEmailRequest.builder()
3237
.source(senderEmail)
3338
.destination(Destination.builder()

src/main/java/ddingdong/ddingdongBE/domain/form/service/FacadeCentralFormServiceImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
import ddingdong.ddingdongBE.domain.form.service.dto.query.MultipleFieldStatisticsQuery.OptionStatisticQuery;
3030
import ddingdong.ddingdongBE.domain.form.service.dto.query.SingleFieldStatisticsQuery;
3131
import ddingdong.ddingdongBE.domain.form.service.dto.query.SingleFieldStatisticsQuery.SingleStatisticsQuery;
32-
import ddingdong.ddingdongBE.domain.form.service.event.SendFormResultEmailEvent;
32+
import ddingdong.ddingdongBE.domain.form.entity.FormResultSendingEmailInfo;
33+
import ddingdong.ddingdongBE.domain.form.service.event.SendFormResultEvent;
3334
import ddingdong.ddingdongBE.domain.formapplication.entity.FormApplication;
3435
import ddingdong.ddingdongBE.domain.formapplication.service.FormAnswerService;
3536
import ddingdong.ddingdongBE.domain.formapplication.service.FormApplicationService;
@@ -191,11 +192,13 @@ public void sendApplicationResultEmail(SendApplicationResultEmailCommand command
191192
command.target()
192193
);
193194
EmailContent emailContent = EmailContent.of(command.title(), command.message(), club);
194-
formApplications.forEach(application -> {
195+
List<FormResultSendingEmailInfo> formResultSendingEmailInfos = formApplications.stream()
196+
.map(application -> {
195197
EmailSendHistory emailSendHistory = emailSendHistoryService.save(EmailSendHistory.createPending(application));
196-
applicationEventPublisher.publishEvent(new SendFormResultEmailEvent(
197-
emailSendHistory.getId(), application.getEmail(), application.getName(), emailContent));
198-
});
198+
return new FormResultSendingEmailInfo(emailSendHistory.getId(), application.getEmail(), application.getName(), emailContent);
199+
})
200+
.toList();
201+
applicationEventPublisher.publishEvent(new SendFormResultEvent(formResultSendingEmailInfos));
199202
}
200203

201204
@Transactional

0 commit comments

Comments
 (0)