feat(seo): 사이트맵 스트리밍 생성 + SEO 캐시 설정 정합화

대용량 사이트에서 사이트맵 생성이 메모리 부족으로 반복 실패하던 문제(공개 )의
1단계로, 전체 URL을 메모리에 적재하던 구조를 스트리밍 분할 생성으로 교체한다.

사이트맵 스트리밍 코어:
- SitemapWriter — 자식 파일 1개 분량만 버퍼링하고 임계 도달 시 flush.
 StorageInterface가 append를 제공하지 않아(put이 전체 덮어쓰기) 택한 구조이며,
 최대 메모리가 "자식 파일 1개 크기"로 유계가 된다. URL 수(50,000)와
 바이트(45MB) 두 임계로 분할해 sitemaps.org 프로토콜을 지킨다.
- 커밋은 _tmp 전량 기록 → live 재배치 → manifest 마지막 기록 순. manifest 존재가
 커밋 완료 신호다. 기존 manifest를 먼저 지우지 않아 스왑 중 봇에게 503이 나가지 않는다.
- SitemapFileStore — 읽기측 + 파일 경로 SSoT. SitemapXmlRenderer — escape 단일 출처.

데이터 접근 계층 정리:
- contributor 3종이 쿼리를 직접 조립하던 것을 Repository 위임으로 전환.
 MySQL 버퍼드 쿼리에서 cursor는 결과셋 전체를 적재하므로 lazyById를 쓴다.
- SeoCacheStatsService → SeoCacheStatRepository 신설 (집계 4쿼리 → 1쿼리).
- audit 룰 service-direct-data-access의 사각 2건 수정 — 확장 디렉토리 정규식이
 상대경로를 매칭하지 못해 *Contributor처럼 접미사 없는 클래스가 전부 미검출이었다.

SEO 캐시 설정 정합화:
- SEO 설정의 캐시 3키가 cache 카테고리 형제 키에 항상 져서 운영자 입력이 조용히
 무시되고 있었다(설정을 cache 카테고리로 이관하며 SEO 탭 옛 칸을 미제거).
 고급 탭을 기준값으로 두되 SEO 탭에 지정이 있으면 오버라이드하도록 SeoCacheSettings
 단일 출처로 정리. "지정 여부"는 null로 판정하므로 기본값을 비웠다.
- 기존 설치는 Upgrade_7_1_0이 이행 — 옛 기본값과 같으면 미설정으로 비우고, 다르면
 운영자 의도로 보아 보존한다.

코어 버전 bump와 루트 CHANGELOG는 계획서 결정(D20)에 따라 마감 단계에서 일괄 수행한다.
This commit is contained in:
HeuJung committed 2026-07-17 19:59:40 +09:00
1 parent fcaacad8d1
commit 21f666e4b5
75 files changed
+4767 -951

No files matched your search

@@ -44,6 +44,7 @@ class PostRepository implements PostRepositoryInterface
* @param array $filters 필터 조건
* @param int $perPage 페이지당 항목 수 (일반 게시글 기준)
* @param bool $withTrashed 삭제된 게시글 포함 여부
* @param Board|null $board 게시판 모델 (이미 조회된 경우 전달하여 중복 쿼리 방지)
* @return Paginator 페이지네이션된 게시글 목록 (simplePaginate — COUNT 쿼리 제거)
*/
public function paginate(string $slug, array $filters = [], int $perPage = 15, bool $withTrashed = false, ?Board $board = null): Paginator
@@ -176,6 +177,7 @@ class PostRepository implements PostRepositoryInterface
*
* @param string $slug 게시판 슬러그
* @param int $id 게시글 ID
* @return Post|null 게시글 모델 (없으면 null)
*/
public function find(string $slug, int $id): ?Post
{
@@ -189,6 +191,7 @@ class PostRepository implements PostRepositoryInterface
*
* @param string $slug 게시판 슬러그
* @param int $id 게시글 ID
* @return Post 게시글 모델
*
* @throws ModelNotFoundException
*/
@@ -205,6 +208,7 @@ class PostRepository implements PostRepositoryInterface
* @param string $slug 게시판 슬러그
* @param int $id 게시글 ID
* @param array $data 수정할 데이터
* @return Post 수정된 게시글 모델
*
* @throws ModelNotFoundException
*/
@@ -221,6 +225,7 @@ class PostRepository implements PostRepositoryInterface
*
* @param string $slug 게시판 슬러그
* @param int $id 게시글 ID
* @return bool 삭제 성공 여부
*
* @throws ModelNotFoundException
*/
@@ -236,6 +241,7 @@ class PostRepository implements PostRepositoryInterface
*
* @param string $slug 게시판 슬러그
* @param int $id 게시글 ID
* @return bool 영구 삭제 성공 여부
*
* @throws ModelNotFoundException
*/
@@ -253,6 +259,8 @@ class PostRepository implements PostRepositoryInterface
* @param int $id 게시글 ID
* @param string $status 변경할 상태 (published/blinded/deleted)
* @param array $actionLog 작업 이력 데이터
* @param string|null $triggerType 트리거 유형 (admin, report 등)
* @return Post 상태가 변경된 게시글 모델
*
* @throws ModelNotFoundException
*/
@@ -406,6 +414,7 @@ class PostRepository implements PostRepositoryInterface
*
* @param string $slug 게시판 슬러그
* @param int $id 게시글 ID
* @param int|null $boardId 게시판 ID (전달 시 Board 재조회 생략)
* @return Post|null 게시글 모델 (카운트 포함)
*/
public function findWithCounts(string $slug, int $id, ?int $boardId = null): ?Post
@@ -554,6 +563,7 @@ class PostRepository implements PostRepositoryInterface
* @param int $id 현재 게시글 ID
* @param array $filters 정렬 파라미터 (order_by, order_direction)
* @param bool $withTrashed 삭제된 게시글 포함 여부 (기본: false)
* @param int|null $boardId 게시판 ID (전달 시 Board 재조회 생략)
* @return array{prev: Post|null, next: Post|null} 이전/다음 게시글
*/
public function getAdjacentPosts(string $slug, int $id, array $filters = [], bool $withTrashed = false, ?int $boardId = null): array
@@ -1391,6 +1401,27 @@ class PostRepository implements PostRepositoryInterface
->find($id);
}
/**
* Sitemap 용으로 게시판의 공개 게시글을 스트리밍 조회합니다.
*
* lazyById 는 id 기준 키셋 페이징으로 청크를 순차 조회하므로,
* 결과셋 전체가 메모리(및 DB 드라이버 버퍼)에 적재되지 않습니다.
*
* @param int $boardId 게시판 ID
* @param int $chunkSize 청크 크기
* @return iterable<Post> 공개 게시글 순회자 (id, updated_at 만 조회)
*/
public function streamPublishedForSitemap(int $boardId, int $chunkSize = 500): iterable
{
return Post::query()
->where('board_id', $boardId)
->where('status', PostStatus::Published)
->where('is_secret', false)
->select(['id', 'updated_at'])
->orderBy('id')
->lazyById($chunkSize);
}
/**
* 게시판 ID 기준으로 게시글을 일괄 소프트 삭제합니다.
*