feat(seo): 사이트맵 기여자 지연 스트리밍 + hreflang 계산 선형화

AbstractSitemapContributor 브리지 base 로 인터페이스를 바꾸지 않고
board/ecommerce/page 기여자를 getUrlsLazy 지연 스트리밍으로 전환해,
게시글이 수백만 건인 사이트에서도 URL 배열을 통째로 적재하지 않는다.
SitemapGenerator 는 capability 를 감지해 지연 경로를 쓰고, base 를
상속하지 않은 제3자 구현체는 기존 getUrls 경로로 그대로 동작한다.

hreflang alternate 집합을 base URL 당 한 번만 계산해 로케일별 <url>
에 재사용하도록 바꿔 계산 비용을 로케일 수의 제곱에서 선형으로 줄였다
(정상 구성 출력은 불변). 다국어 대체 링크 사용 여부 토글과 로케일 수
상한을 추가하고 설정/검증/관리자 UI/다국어(ko·en·ja) 표면을 동반했다.
This commit is contained in:
HeuJung committed 2026-07-18 15:05:56 +09:00
1 parent 1c99547bc1
commit 1a6fca0d6b
28 files changed
+726 -179

No files matched your search

+61
View File
@@ -2,6 +2,7 @@
namespace Tests\Unit\Seo;
use App\Seo\AbstractSitemapContributor;
use App\Seo\Contracts\SitemapContributorInterface;
use App\Seo\SitemapGenerator;
use App\Seo\SitemapWriter;
@@ -649,6 +650,66 @@ class SitemapGeneratorTest extends TestCase
$this->assertContains(url('/ok'), array_column($writer->entries, 'loc'));
}
// ─── drain capability 감지 (지연 스트리밍) ─────────────
/**
* getUrlsLazy 를 가진 기여자는 지연 경로로 소진된다 (getUrls 미호출).
*
* getUrls() 를 호출하면 예외를 던지는 기여자를 사용해, generateToWriter 가
* 지연 경로(getUrlsLazy)만 탄다는 것을 증명한다.
*/
public function test_generate_to_writer_uses_lazy_path_for_capable_contributor(): void
{
Log::shouldReceive('warning')->zeroOrMoreTimes();
$contributor = new class extends AbstractSitemapContributor
{
public function getIdentifier(): string
{
return 'lazy-capable';
}
public function getUrls(): array
{
throw new \LogicException('getUrls() 는 지연 경로에서 호출되면 안 됩니다.');
}
public function getUrlsLazy(): iterable
{
yield ['url' => '/lazy/1'];
yield ['url' => '/lazy/2'];
}
};
$this->generator->registerContributor($contributor);
$writer = new SpySitemapWriter;
$this->generator->generateToWriter($writer);
$locs = array_column($writer->entries, 'loc');
$this->assertContains(url('/lazy/1'), $locs);
$this->assertContains(url('/lazy/2'), $locs);
}
/**
* getUrlsLazy 가 없는 raw 기여자는 기존 getUrls() 경로로 소진된다 (하위호환).
*/
public function test_generate_to_writer_uses_get_urls_for_raw_contributor(): void
{
Log::shouldReceive('warning')->zeroOrMoreTimes();
$contributor = Mockery::mock(SitemapContributorInterface::class);
$contributor->shouldReceive('getIdentifier')->andReturn('raw-module');
$contributor->shouldReceive('getUrls')->once()->andReturn([['url' => '/raw/1']]);
$this->generator->registerContributor($contributor);
$writer = new SpySitemapWriter;
$this->generator->generateToWriter($writer);
$this->assertContains(url('/raw/1'), array_column($writer->entries, 'loc'));
}
// ─── 헬퍼 메서드 ──────────────────────────────────────
/**