From 27d89f35a2c136d09436eba6ae7dff8e0656910a Mon Sep 17 00:00:00 2001 From: "sungjin.choi" Date: Thu, 26 Nov 2026 13:28:49 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=ED=99=88=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20=EA=B5=90=EC=B2=B4=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../company/specialsource/config/SecurityConfig.java | 2 +- .../scraper/ScrapedPostSyncService.java | 12 +++++++++--- src/main/resources/application.yaml | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/company/specialsource/config/SecurityConfig.java b/src/main/java/company/specialsource/config/SecurityConfig.java index 43704f0..8d86b25 100644 --- a/src/main/java/company/specialsource/config/SecurityConfig.java +++ b/src/main/java/company/specialsource/config/SecurityConfig.java @@ -44,7 +44,7 @@ public class SecurityConfig { @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration config = new CorsConfiguration(); - config.setAllowedOriginPatterns(List.of("http://localhost:*", "https://new.specialsource.company")); + config.setAllowedOriginPatterns(List.of("http://localhost:*", "https://specialsource.company", "https://www.specialsource.company", "https://new.specialsource.company")); config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); config.setAllowedHeaders(List.of("*")); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); diff --git a/src/main/java/company/specialsource/scraper/ScrapedPostSyncService.java b/src/main/java/company/specialsource/scraper/ScrapedPostSyncService.java index 8382702..73401ad 100644 --- a/src/main/java/company/specialsource/scraper/ScrapedPostSyncService.java +++ b/src/main/java/company/specialsource/scraper/ScrapedPostSyncService.java @@ -4,10 +4,12 @@ import company.specialsource.entity.ScrapedPost; import company.specialsource.repository.ScrapedPostRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; /** * 목록에 새로 나타난 글만 상세페이지까지 들어가서 본문을 수집한다. @@ -18,11 +20,15 @@ import java.util.List; @RequiredArgsConstructor public class ScrapedPostSyncService { - private static final long DELAY_BETWEEN_DETAIL_FETCHES_MS = 800; - private final ScrapedPostRepository scrapedPostRepository; private final PostDetailScraperService postDetailScraperService; + // 상세페이지 요청 사이 대기: min~max 사이 랜덤 + @Value("${scraping.detail-delay-min-ms:3000}") + private long detailDelayMinMs; + @Value("${scraping.detail-delay-max-ms:6000}") + private long detailDelayMaxMs; + public int saveNewPosts(BoardSource source, List posts) { int savedCount = 0; for (ScrapedPostDto post : posts) { @@ -64,7 +70,7 @@ public class ScrapedPostSyncService { private void sleepQuietly() { try { - Thread.sleep(DELAY_BETWEEN_DETAIL_FETCHES_MS); + Thread.sleep(ThreadLocalRandom.current().nextLong(detailDelayMinMs, detailDelayMaxMs + 1)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 3199aee..0cf9a54 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -42,6 +42,8 @@ scraping: initial-delay-ms: 10000 # 앱 기동 후 첫 스크래핑까지 대기 시간 interval-min-ms: 600000 # 게시판 전체 스크래핑 주기: 이전 실행이 끝난 뒤 min~max 사이 랜덤 (10~20분) interval-max-ms: 1200000 + detail-delay-min-ms: 3000 # 새 글 상세페이지 요청 사이 대기: min~max 사이 랜덤 (3~6초) + detail-delay-max-ms: 6000 retention-days: 7 # 이 기간(scraped_at 기준)이 지난 게시물은 자동 삭제 cleanup-initial-delay-ms: 60000 # 앱 기동 후 첫 정리 작업까지 대기 시간 cleanup-interval-ms: 86400000 # 정리 작업 주기 (24시간) \ No newline at end of file