feat(core,engine): 부트스트랩 리소스 정적 게시(bake) 및 폴백 체계 도입
공개 제보 https://github.com/gnuboard/g7/issues/122 대응 — 초기 부트스트랩 리소스(다국어 병합·컴포넌트 정의·라우트·확장 번들·템플릿 dist)를 캐시 버전 디렉토리(public/build/ext/{v}/)에 실파일로 게시해 웹서버가 rewrite 전에 직접 서빙한다. 부트 임계 경로의 PHP 왕복을 제거하고(실측 TTFB 131~144ms → 1~7ms), 미게시·부분게시·GC 직후에는 fetch·태그·번들 3계층이 종전 API 로 즉시 폴백한다. - 게시: 원자적 tmp→rename→manifest(존재=완료), 캐시 락 단일 실행, 인라인 GC (현재+직전 1개), incrementExtensionCacheVersion 단일 지점 terminating 트리거 + blade 자가 치유 + 설치기 태스크(best_effort) + 일일 cleanup 스케줄, sudo 업데이트 대비 소유권 정상화(normalizeOwnership)·prune/백업 제외 - 프론트(engine-v1.61.0): blade 주입 cache_version 1급 시드(이중 부트 로드 제거), fetchStaticFirst 즉시 폴백, ComponentRegistry 버전 키드 매니페스트, ModuleAssetLoader 번들 정적→레거시 폴백, asset-url-recovery staticToLegacy 역변환 - 폴백 API 품질: lang/components/routes ETag+304 + 환경 분기 Cache-Control, 열화 라우트 스냅샷 공개 캐시 금지(서버측 캐시 회피와 대칭), 게시 .htaccess mod_deflate + nginx gzip 스니펫(압축 전송량 회귀 방지) - SEO 정합: 봇 HTML 은 GC 대상 정적 URL 미사용(allowStatic:false), props $switch 봇측 해석 구현(engine-v1.56.0 패리티), 패리티 룰 expression-dialect 그룹 신설, 상주 allow 헤더 제거로 잠금 복원, _comment* 접두 주석 키 분류 - 검증: 전 수정 red→green 4단계, Playwright 라이브 21건, Chrome MCP 24축+M1~M3, 봇 curl 3축, 캐시 저장소(file/redis/database) 축 판정, 히스토리·공개이슈·커밋 이력 전수 재조사 반영 - 코어 7.0.10, engine-v1.61.0. kill-switch: G7_STATIC_CACHE=false
This commit is contained in:
1 parent
56836a2b66
commit
5ba7a83597
73 files changed
+4219
-98
No files matched your search
+147
-2
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Services\ExtensionStaticCacheService;
|
||||
use App\Support\Routing\DualExtensionRoute;
|
||||
|
||||
/**
|
||||
@@ -59,6 +60,23 @@ class AssetUrl
|
||||
*/
|
||||
private static ?string $modeOverride = null;
|
||||
|
||||
/**
|
||||
* 정적 게시(bake) 베이스 경로 메모 (요청당 1회 판정).
|
||||
*/
|
||||
private static ?string $staticExtBaseMemo = null;
|
||||
|
||||
/**
|
||||
* 정적 게시 베이스 판정 완료 여부.
|
||||
*/
|
||||
private static bool $staticExtBaseResolved = false;
|
||||
|
||||
/**
|
||||
* 태그 계층 파일 단위 게이트 메모 (상대 경로 => 존재 여부).
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
private static array $staticFileMemo = [];
|
||||
|
||||
/**
|
||||
* 현재 자산 URL 모드를 반환합니다.
|
||||
*
|
||||
@@ -103,6 +121,105 @@ class AssetUrl
|
||||
self::$modeOverride = $mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 정적 게시(bake) 베이스 경로를 반환합니다 (#122).
|
||||
*
|
||||
* 게이트 3조건 — ① 프로덕션 ② `core.static_cache.enabled` ③ 현재 버전 게시
|
||||
* 완료(manifest 존재) — 을 전부 통과할 때만 `/build/ext/{v}` 를 반환한다.
|
||||
* 아니면 null (종전 API URL 방출). 요청당 1회 판정 후 메모이즈한다.
|
||||
*
|
||||
* 자가 치유 — 프로덕션인데 현재 버전이 미게시면 terminating 게시를 예약한다.
|
||||
* 이번 응답은 종전 API URL 로 나가고(첫 방문자 1회만 종전 속도), 다음
|
||||
* 렌더부터 정적 fast path 가 적용된다.
|
||||
*
|
||||
* blade 렌더 경로에서 호출되므로 어떤 실패도 예외로 새 나가면 안 된다.
|
||||
*
|
||||
* @return string|null 정적 베이스 경로 또는 null
|
||||
*/
|
||||
public static function staticExtBase(): ?string
|
||||
{
|
||||
if (self::$staticExtBaseResolved) {
|
||||
return self::$staticExtBaseMemo;
|
||||
}
|
||||
|
||||
self::$staticExtBaseResolved = true;
|
||||
self::$staticExtBaseMemo = null;
|
||||
|
||||
try {
|
||||
if (! app()->environment('production')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! (bool) config('core.static_cache.enabled', true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 트레이트 정적 메서드 직접 호출(ClearsTemplateCaches::)은 PHP 8.1+ E_DEPRECATED
|
||||
// — 트레이트를 사용하는 클래스 경유로 호출한다 (게이트·게시자가 같은 static
|
||||
// 스토어 메모 슬롯을 공유하게 되는 부수 이점도 있다)
|
||||
$version = ExtensionStaticCacheService::getExtensionCacheVersion();
|
||||
|
||||
if (! app(ExtensionStaticCacheService::class)->isPublished($version)) {
|
||||
// 자가 치유 — 응답 종료 후 게시 시도 (실패해도 API 폴백으로 정상)
|
||||
ExtensionStaticCacheService::schedulePublishOnTerminate();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
self::$staticExtBaseMemo = '/build/ext/'.$version;
|
||||
} catch (\Throwable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return self::$staticExtBaseMemo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 정적 게시 베이스 메모를 초기화합니다 (테스트 전용).
|
||||
*/
|
||||
public static function resetStaticExtBaseMemo(): void
|
||||
{
|
||||
self::$staticExtBaseResolved = false;
|
||||
self::$staticExtBaseMemo = null;
|
||||
self::$staticFileMemo = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 정적 게시본 내 파일 존재 여부를 확인합니다 (태그 계층 파일 단위 게이트).
|
||||
*
|
||||
* `<link>`/`<script>` 태그는 404 를 받아도 스스로 재시도하지 못하므로,
|
||||
* manifest 게이트에 더해 그 자산의 실파일 존재까지 확인한 뒤에만 정적 URL 을
|
||||
* 방출한다 (요청당 태그 대상 ~6개 파일, 메모이즈).
|
||||
*
|
||||
* @param string $relative 게시 트리 상대 경로
|
||||
* @return bool 파일 존재 여부
|
||||
*/
|
||||
private static function staticFileExists(string $relative): bool
|
||||
{
|
||||
$version = substr((string) self::$staticExtBaseMemo, strlen('/build/ext/'));
|
||||
|
||||
return self::$staticFileMemo[$relative] ??= is_file(
|
||||
public_path('build/ext/'.$version.'/'.$relative)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 태그 계층 자산의 정적 게시 URL 을 반환합니다 (파일 존재 확인 포함).
|
||||
*
|
||||
* @param string $relative 게시 트리 상대 경로
|
||||
* @return string|null 정적 URL 또는 null (게이트 미통과)
|
||||
*/
|
||||
private static function staticTagUrl(string $relative): ?string
|
||||
{
|
||||
$base = self::staticExtBase();
|
||||
|
||||
if ($base === null || ! self::staticFileExists($relative)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $base.'/'.$relative;
|
||||
}
|
||||
|
||||
/**
|
||||
* 템플릿 자산 URL 을 생성합니다.
|
||||
*
|
||||
@@ -112,11 +229,28 @@ class AssetUrl
|
||||
* @param string $identifier 템플릿 식별자
|
||||
* @param string $path `dist/` 이하 파일 경로 (예: `js/components.iife.js`)
|
||||
* @param int|string|null $version 캐시 무효화 버전 (null 이면 미부착)
|
||||
* @param bool $allowStatic 정적 게시본(bake) 경로 허용 여부. 생성한 URL 이 정적
|
||||
* 게시 GC(현재+직전 1개 보존)보다 오래 사는 저장소에 박제되는
|
||||
* 호출부(SEO 페이지 캐시 등)는 false 로 종전 API URL 을 받는다
|
||||
* @return string 생성된 URL
|
||||
*/
|
||||
public static function templateAsset(string $identifier, string $path, int|string|null $version = null): string
|
||||
public static function templateAsset(string $identifier, string $path, int|string|null $version = null, bool $allowStatic = true): string
|
||||
{
|
||||
return self::asset('templates', $identifier, $path, $version);
|
||||
// 정적 게시본(bake) 우선 (#122) — 버전 디렉토리 경로라 `?v` 쿼리가 불필요하다.
|
||||
// 게이트(프로덕션·kill-switch·게시 완료·개별 파일 존재) 미통과 시 종전 URL 그대로.
|
||||
// `$version` 이 현재 게시 버전과 다르면 정적 분기를 건너뛴다 — 정적 경로는 항상
|
||||
// 현재 게시본이므로, 다른 버전을 명시한 호출에 현재본을 주면 "요청 버전이 URL 에
|
||||
// 반영된다" 는 시그니처 계약이 조용히 깨진다 (현 호출부는 전부 현재 버전 전달).
|
||||
$static = null;
|
||||
if ($allowStatic) {
|
||||
$base = self::staticExtBase();
|
||||
|
||||
if ($base !== null && ($version === null || $base === '/build/ext/'.$version)) {
|
||||
$static = self::staticTagUrl('templates/'.$identifier.'/assets/'.ltrim($path, '/'));
|
||||
}
|
||||
}
|
||||
|
||||
return $static ?? self::asset('templates', $identifier, $path, $version);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,6 +312,17 @@ class AssetUrl
|
||||
*/
|
||||
public static function extensionBundle(string $type, string $kind, int|string|null $version = null): string
|
||||
{
|
||||
// 정적 게시본(bake) 우선 (#122) — `bundles/{modules|plugins}.{js|css}` 사본.
|
||||
// `$version` 명시 호출이 현재 게시 버전과 다르면 건너뛴다 (templateAsset 과 동일 계약)
|
||||
$base = self::staticExtBase();
|
||||
$static = $base !== null && ($version === null || $base === '/build/ext/'.$version)
|
||||
? self::staticTagUrl("bundles/{$type}.{$kind}")
|
||||
: null;
|
||||
|
||||
if ($static !== null) {
|
||||
return $static;
|
||||
}
|
||||
|
||||
$base = self::isExtensionless()
|
||||
? "/api/{$type}/bundle/{$kind}"
|
||||
: "/api/{$type}/bundle.{$kind}";
|
||||
|
||||
Reference in new issue
Block a user