-
Notifications
You must be signed in to change notification settings - Fork 2
prod : 인증 인가 부분 수정 및 배포 (Redis 구성 공통화) #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dd69103
15580b0
516efda
7a4b055
51c8e7b
e37be02
1bcb134
1ccfd98
ece06ed
5bc3998
4df6718
be9b81c
b3421cd
0f3198d
0700fce
46a6bac
dafcc96
1983734
bde3392
722d9c1
a02c2ab
4e5fba1
9156dae
a23d073
72d05de
4f76947
3a9f056
bc5b811
22ddb8b
9904a69
791ff20
003ce2f
c0d23ea
ef2a45f
7c3b84a
546d6ce
9d6003d
6c4dcd2
8db0333
7c0d2b7
fb7a598
e5076ec
211511b
1daba52
4233ed8
795a6e9
6ea148a
9e44526
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package life.mosu.mosuserver.application.caffeine; | ||
|
|
||
| import com.github.benmanes.caffeine.cache.Cache; | ||
| import java.time.Duration; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import life.mosu.mosuserver.domain.caffeine.dto.BlockedIpHistory; | ||
| import life.mosu.mosuserver.domain.caffeine.entity.BlockedIpHistoryLogJpaEntity; | ||
| import life.mosu.mosuserver.domain.caffeine.repository.BlockedIpHistoryLogJpaJpaRepository; | ||
| import life.mosu.mosuserver.global.filter.TimePenalty; | ||
| import life.mosu.mosuserver.global.support.cron.DomainArchiveExecutor; | ||
| import life.mosu.mosuserver.infra.cron.annotation.CronTarget; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| @Slf4j | ||
| @CronTarget | ||
| @RequiredArgsConstructor | ||
| public class BlockedIpBatchAchiever implements DomainArchiveExecutor { | ||
|
|
||
| private final static Duration DURATION_HOURS_STANDARD = Duration.ofHours(1); | ||
| private final static int BATCH_SIZE = 500; | ||
|
|
||
| private final BlockedIpHistoryLogJpaJpaRepository blockedIpHistoryLogJpaRepository; | ||
| private final Cache<String, BlockedIpHistory> blockedHistoryCache; | ||
|
|
||
|
|
||
| @Override | ||
| public void archive() { | ||
| Map<String, BlockedIpHistory> blockedHistoryMap = blockedHistoryCache.asMap(); | ||
|
|
||
| List<BlockedIpHistoryLogJpaEntity> logs = blockedHistoryMap.values().stream() | ||
| .filter(entry -> entry.getPenaltyLevel() == TimePenalty.LEVEL_5) | ||
| .map(this::createBlockedHistoryLog) | ||
| .toList(); | ||
|
|
||
| if (logs.isEmpty()) { | ||
| log.debug("[BlockedIpArchiver] 저장할 로그가 없음."); | ||
| return; | ||
| } | ||
|
|
||
| for (int i = 0; i < logs.size(); i += BATCH_SIZE) { | ||
| int end = Math.min(i + BATCH_SIZE, logs.size()); | ||
| List<BlockedIpHistoryLogJpaEntity> batch = logs.subList(i, end); | ||
|
|
||
| try { | ||
| blockedIpHistoryLogJpaRepository.saveAllUsingBatch(batch); | ||
| log.debug("[BlockedIpArchiver] 저장 완료: {}개", batch.size()); | ||
| } catch (Exception e) { | ||
| log.error("[BlockedIpArchiver] 저장 실패: {}~{} 인덱스", i, end, e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "blocked-ip"; | ||
| } | ||
|
|
||
| private BlockedIpHistoryLogJpaEntity createBlockedHistoryLog( | ||
| BlockedIpHistory blockedIpHistory) { | ||
| return new BlockedIpHistoryLogJpaEntity( | ||
| blockedIpHistory.getIp(), | ||
| blockedIpHistory.getPenaltyLevel(), | ||
| blockedIpHistory.getBlockedAt() | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -68,11 +68,9 @@ public void deleteInquiry(UserJpaEntity user, Long postId) { | |||||
| InquiryJpaEntity inquiry = getInquiry(postId); | ||||||
| hasPermission(inquiry.getUserId(), user); | ||||||
|
|
||||||
| inquiryAnswerJpaRepository.findByInquiryId(postId).ifPresent(answer -> { | ||||||
| inquiryAnswerService.deleteInquiryAnswer(postId); | ||||||
| }); | ||||||
| inquiryAnswerService.deleteInquiryAnswer(postId); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When deleting an inquiry, it's possible that it doesn't have an answer. The previous implementation handled this case gracefully by using
Suggested change
|
||||||
|
|
||||||
| // inquiryAttachmentService.deleteAttachment(inquiry); | ||||||
| inquiryAttachmentService.deleteAttachment(inquiry); | ||||||
| inquiryJpaRepository.delete(inquiry); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation of the
archivemethod collects all matching log entries into a list before processing them in batches. If theblockedHistoryCachecontains a very large number of entries, this could lead to high memory consumption.A more memory-efficient approach would be to iterate through the cache entries and build batches on the fly, without creating a large intermediate list.