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