fix(core): 레이아웃 버전 변경량 계산의 메모리 초과와 편집기 확장 편집·재로드·충돌 안내·버전 기록 결함 수정
- 버전 이력 변경량(+N/-N 줄) 계산이 변경 영역 (줄 수)² 크기의 LCS 표를 만들어 큰 공통 레이아웃의 첫 편집기 저장이 PHP 기본 메모리 한도(128M) 서버에서 500 으로 끝났다. 두 행 DP 로 길이만 구하도록 바꿔 메모리가 줄 수에 비례하고 표시 숫자는 종전과 같다(참조 구현 동치·메모리 상한 회귀 테스트) - 확장 편집 모드 저장이 overlay 확장의 injections 를 비우던 결함: 서버가 주입 노드 출처 메타에 injection 순번을 싣고, 편집기는 그 순번(없으면 원본 노드 id) 으로 되돌리며, 되돌릴 수 없는 노드가 있으면 저장하지 않고 안내한다 - 서빙 캐시 키를 서버 현재 확장 캐시 버전으로만 조립해 저장·복원 두 번째부터 재로드·「최신 불러오기」가 옛 내용을 받던 결함 수정(요청 v 는 HTTP 캐시 우회용) - 409 충돌 안내가 errors 아래의 버전을 읽지 못해 「최신 버전: -1」 로 표시되던 결함을 세 저장 경로 공용 판독으로 수정 - 버전 저장 시 저장자를 기록하고, 복원 시에도 잠금 번호를 올린다 - 회귀 테스트(PHPUnit·Vitest), 트러블슈팅 사례 32~34, 규정·API 문서, ja 언어팩, 편집기 번들 재빌드, 이력 문서 동반
This commit is contained in:
1 parent
72f46a6468
commit
0b6f329249
34 files changed
+1080
-97
No files matched your search
@@ -14,9 +14,10 @@ interface LayoutExtensionVersionRepositoryInterface
|
||||
* @param int $extensionId 레이아웃 확장 ID
|
||||
* @param array $oldContent 이전 콘텐츠
|
||||
* @param array|null $newContent 새 콘텐츠 (null이면 현재 확장 content 사용)
|
||||
* @param int|null $createdBy 저장자 ID (null 이면 현재 인증 사용자)
|
||||
* @return TemplateLayoutExtensionVersion 생성된 버전 모델
|
||||
*/
|
||||
public function saveVersion(int $extensionId, array $oldContent, ?array $newContent = null): TemplateLayoutExtensionVersion;
|
||||
public function saveVersion(int $extensionId, array $oldContent, ?array $newContent = null, ?int $createdBy = null): TemplateLayoutExtensionVersion;
|
||||
|
||||
/**
|
||||
* 특정 확장의 모든 버전 조회 (최신순)
|
||||
|
||||
@@ -14,9 +14,10 @@ interface LayoutVersionRepositoryInterface
|
||||
* @param int $layoutId 레이아웃 ID
|
||||
* @param array $oldContent 이전 콘텐츠
|
||||
* @param array|null $newContent 새 콘텐츠 (null이면 현재 레이아웃 content 사용)
|
||||
* @param int|null $createdBy 저장자 ID (null 이면 현재 인증 사용자)
|
||||
* @return TemplateLayoutVersion 생성된 버전 모델
|
||||
*/
|
||||
public function saveVersion(int $layoutId, array $oldContent, ?array $newContent = null): TemplateLayoutVersion;
|
||||
public function saveVersion(int $layoutId, array $oldContent, ?array $newContent = null, ?int $createdBy = null): TemplateLayoutVersion;
|
||||
|
||||
/**
|
||||
* 특정 레이아웃의 모든 버전 조회 (최신순)
|
||||
|
||||
@@ -63,20 +63,18 @@ class PublicLayoutController extends PublicBaseController
|
||||
}
|
||||
|
||||
try {
|
||||
// 캐시 버전을 키에 포함하여 모듈/플러그인 변경 시 캐시 무효화.
|
||||
// 서버 캐시 키는 **서버 현재** 확장 캐시 버전으로만 조립한다. 클라이언트 `?v=` 는 브라우저
|
||||
// HTTP 캐시 우회용 좌표일 뿐 서버 키의 근거가 아니다.
|
||||
//
|
||||
// 서버 캐시 키에는 **정수 버전만** 쓴다(소수 nonce 제거). 레이아웃 편집기는 같은 세션의
|
||||
// 저장·버전 복원 직후 브라우저 HTTP 캐시를 우회하려고 `?v={cacheVersion}.{nonce}` 형식으로
|
||||
// 요청한다(클라이언트 cache-bust nonce). 그런데 `serve` 가 이 문자열을 그대로 캐시 키에
|
||||
// 쓰면 키가 `...v{cacheVersion}.{nonce}.meta` 가 되는데, 저장 경로
|
||||
// `LayoutService::clearPublicServingCache` 는 `(int) ext.cache_version` 으로 nonce 없는
|
||||
// 키만 forget 하므로 키 형식이 어긋나 무효화가 빗나간다(저장/복원 후 편집기 캔버스만
|
||||
// stale). nonce 는 브라우저 HTTP 캐시 우회용(URL·ETag 차이로 이미 달성)이고, 서버 캐시 키
|
||||
// 정합은 정수 버전이 SSoT 다. `(int)` 캐스팅은 PHP 가 소수점에서 절단해 정수부만 남긴다.
|
||||
// `?v` 생략 시 현재 버전으로 폴백 — 리터럴 0 폴백은 워밍/무효화 어느 경로에도
|
||||
// 걸리지 않는 `.v0` 영구 사각 키를 만든다 (#588).
|
||||
$rawVersion = request()->query('v');
|
||||
$cacheVersion = $rawVersion !== null ? (int) $rawVersion : self::getExtensionCacheVersion();
|
||||
// 종전엔 `?v` 의 정수부를 키에 썼다(#588 — nonce 제거). 그런데 레이아웃 편집기는 부팅
|
||||
// 시점 `window.G7Config.cache_version` 에 nonce 만 붙여 계속 요청하고, 저장·복원은
|
||||
// `ext.cache_version` 을 `time()` 으로 올리며 `clearPublicServingCache` 는 **현재** 버전
|
||||
// 키만 지운다. 그래서 두 번째 bump 부터 부팅 버전 키가 영영 지워지지 않아 초기화·복원·
|
||||
// 409 「최신 불러오기」가 옛 content 를 받았고(실측: 초기화 직후 lock 4 응답, DB 는 lock 7),
|
||||
// 그 화면을 다시 저장하면 옛 내용이 최신을 덮을 수 있었다. 서버 버전으로 키를 고정하면
|
||||
// 무효화(현재 버전 키 forget)와 굽기(현재 버전 키 remember)가 같은 키를 본다. `?v` 가 어떤
|
||||
// 값이든 결과는 같고, 이전 버전 키는 bump 로 자연 이탈한다(TTL 만료).
|
||||
$cacheVersion = self::getExtensionCacheVersion();
|
||||
|
||||
// 편집기 출처 메타 옵션
|
||||
// - 옵션이 truthy 면 각 노드에 `__source` 메타를 부여한 응답을 반환
|
||||
|
||||
@@ -135,10 +135,17 @@ trait CalculatesJsonContentDiff
|
||||
/**
|
||||
* 라인 배열 두 개의 LCS diff — 추가/삭제 라인 "수"를 반환한다.
|
||||
*
|
||||
* 공통 prefix/suffix 를 먼저 트리밍해 LCS DP 입력을 변경 영역으로 축소한다(큰
|
||||
* content 의 작은 변경도 빠르게 처리). 라인 원문은 누적하지 않고 카운트만 세므로
|
||||
* 메모리도 절약된다(저장 대상은 카운트뿐). 프론트 computeLineDiff 와 동일 전략이라
|
||||
* added/removed 카운트가 일치한다.
|
||||
* 공통 prefix/suffix 를 먼저 트리밍해 LCS 입력을 변경 영역으로 축소한다(큰 content 의
|
||||
* 작은 변경도 빠르게 처리). 카운트는 LCS **길이**만으로 결정된다 — 추가 = 새 줄 수 − LCS,
|
||||
* 삭제 = 옛 줄 수 − LCS — 이므로 표 전체를 만들어 되짚을 필요가 없고, 두 행만 쓰는
|
||||
* 길이 계산으로 메모리를 변경 영역 줄 수에 비례하게 묶는다. 프론트 computeLineDiff 는
|
||||
* 실제 diff 줄을 그려야 해서 전체 표를 쓰지만 같은 LCS 규칙이므로 added/removed 카운트가
|
||||
* 일치한다.
|
||||
*
|
||||
* 트리밍은 양끝이 동시에 바뀌면 무력하다 — 편집기는 저장 시 `comment` 키를 떼어내므로
|
||||
* 큰 공통 레이아웃의 첫 편집기 저장은 변경 영역이 파일 전체(2,000줄 이상)가 된다.
|
||||
* 종전의 (줄 수)² PHP 배열은 그 경우 약 150MB 를 써서 PHP 기본 memory_limit(128M)
|
||||
* 서버에서 저장이 500 으로 끝났다(개발 머신은 512M 이라 드러나지 않았다).
|
||||
*
|
||||
* @param array<string> $a 이전 라인
|
||||
* @param array<string> $b 새 라인
|
||||
@@ -172,43 +179,50 @@ trait CalculatesJsonContentDiff
|
||||
$nb = count($midB);
|
||||
|
||||
// 안전 가드 — 변경 영역이 과대하면 LCS 를 생략하고 라인 집합 차집합으로 근사한다.
|
||||
// 프론트 lineDiff.ts 의 DIFF_MAX_LINES(4000) 와 동일 임계. 인접 버전 비교는 변경
|
||||
// 영역이 작아 이 경로를 타지 않으며, 비정상적으로 큰 변경에서만 O(n·m) DP 를 회피한다.
|
||||
// 프론트 lineDiff.ts 의 DIFF_MAX_LINES(4000) 와 동일 임계. 시간 O(n·m) 의 상한이며,
|
||||
// 아래 길이 계산은 메모리가 두 행뿐이라 이 임계 안에서는 memory_limit 과 무관하다.
|
||||
if ($na > self::DIFF_MAX_LINES || $nb > self::DIFF_MAX_LINES) {
|
||||
return $this->approximateLineCounts($midA, $midB);
|
||||
}
|
||||
|
||||
// LCS DP
|
||||
$dp = array_fill(0, $na + 1, array_fill(0, $nb + 1, 0));
|
||||
$lcs = $this->lcsLength($midA, $midB);
|
||||
|
||||
return [$nb - $lcs, $na - $lcs];
|
||||
}
|
||||
|
||||
/**
|
||||
* 두 라인 배열의 LCS(최장 공통 부분수열) 길이 — 두 행만 쓰는 DP.
|
||||
*
|
||||
* 전체 표(종전 `$dp[$i][$j]`)와 같은 점화식(`a[i] === b[j] ? next[j+1] + 1 : max(next[j],
|
||||
* cur[j+1])`)을 행 단위로 굴려 마지막 행의 첫 칸만 남긴다. 되짚기(backtrack)가 필요한
|
||||
* 프론트 diff 뷰와 달리 여기서는 길이만 쓰므로 카운트가 종전과 정확히 같다.
|
||||
*
|
||||
* @param array<int, string> $a 이전 라인 (0 부터 연속 인덱스)
|
||||
* @param array<int, string> $b 새 라인 (0 부터 연속 인덱스)
|
||||
* @return int LCS 길이
|
||||
*/
|
||||
private function lcsLength(array $a, array $b): int
|
||||
{
|
||||
$na = count($a);
|
||||
$nb = count($b);
|
||||
|
||||
if ($na === 0 || $nb === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$next = array_fill(0, $nb + 1, 0);
|
||||
for ($i = $na - 1; $i >= 0; $i--) {
|
||||
$cur = array_fill(0, $nb + 1, 0);
|
||||
$line = $a[$i];
|
||||
for ($j = $nb - 1; $j >= 0; $j--) {
|
||||
$dp[$i][$j] = $midA[$i] === $midB[$j]
|
||||
? $dp[$i + 1][$j + 1] + 1
|
||||
: max($dp[$i + 1][$j], $dp[$i][$j + 1]);
|
||||
$cur[$j] = $line === $b[$j]
|
||||
? $next[$j + 1] + 1
|
||||
: max($next[$j], $cur[$j + 1]);
|
||||
}
|
||||
$next = $cur;
|
||||
}
|
||||
|
||||
// backtrack — 삭제/추가 라인 수만 카운트
|
||||
$added = 0;
|
||||
$removed = 0;
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
while ($i < $na && $j < $nb) {
|
||||
if ($midA[$i] === $midB[$j]) {
|
||||
$i++;
|
||||
$j++;
|
||||
} elseif ($dp[$i + 1][$j] >= $dp[$i][$j + 1]) {
|
||||
$removed++;
|
||||
$i++;
|
||||
} else {
|
||||
$added++;
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
$removed += $na - $i;
|
||||
$added += $nb - $j;
|
||||
|
||||
return [$added, $removed];
|
||||
return $next[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\TemplateLayoutExtensionVersion;
|
||||
use App\Repositories\Concerns\CalculatesJsonContentDiff;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LayoutExtensionVersionRepository implements LayoutExtensionVersionRepositoryInterface
|
||||
@@ -28,9 +29,10 @@ class LayoutExtensionVersionRepository implements LayoutExtensionVersionReposito
|
||||
* @param int $extensionId 레이아웃 확장 ID
|
||||
* @param array $content 저장할 content 스냅샷
|
||||
* @param array|null $previousContent 직전 버전 content (변경 요약 기준). null 이면 변경 요약 0
|
||||
* @param int|null $createdBy 저장자 ID (null 이면 현재 인증 사용자)
|
||||
* @return TemplateLayoutExtensionVersion 생성된 버전
|
||||
*/
|
||||
public function saveVersion(int $extensionId, array $content, ?array $previousContent = null): TemplateLayoutExtensionVersion
|
||||
public function saveVersion(int $extensionId, array $content, ?array $previousContent = null, ?int $createdBy = null): TemplateLayoutExtensionVersion
|
||||
{
|
||||
$nextVersion = $this->getNextVersion($extensionId);
|
||||
|
||||
@@ -44,6 +46,8 @@ class LayoutExtensionVersionRepository implements LayoutExtensionVersionReposito
|
||||
'version' => $nextVersion,
|
||||
'content' => $content,
|
||||
'changes_summary' => $changesSummary,
|
||||
// 저장자 — 버전 목록의 「저장자」 표시 근거. 종전엔 기록하지 않아 항상 「알 수 없음」이었다.
|
||||
'created_by' => $createdBy ?? Auth::id(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -165,9 +169,10 @@ class LayoutExtensionVersionRepository implements LayoutExtensionVersionReposito
|
||||
$extension = LayoutExtension::findOrFail($extensionId);
|
||||
$currentContent = $extension->content;
|
||||
|
||||
// 3. 확장을 복원할 content로 업데이트
|
||||
// 3. 확장을 복원할 content로 업데이트 — lock_version 도 올린다(레이아웃 본체와 동형).
|
||||
$extension->update([
|
||||
'content' => $versionToRestore->content,
|
||||
'lock_version' => ((int) ($extension->lock_version ?? 0)) + 1,
|
||||
]);
|
||||
|
||||
// 4. 복원 결과를 새 버전으로 저장 — content 는 복원된 내용, changes_summary 는 복원
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\TemplateLayoutVersion;
|
||||
use App\Repositories\Concerns\CalculatesJsonContentDiff;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class LayoutVersionRepository implements LayoutVersionRepositoryInterface
|
||||
@@ -28,9 +29,10 @@ class LayoutVersionRepository implements LayoutVersionRepositoryInterface
|
||||
* @param int $layoutId 레이아웃 ID
|
||||
* @param array $content 저장할 content 스냅샷 (이 버전이 담는 내용)
|
||||
* @param array|null $previousContent 직전 버전 content (변경 요약 기준). null 이면 변경 요약 0
|
||||
* @param int|null $createdBy 저장자 ID (null 이면 현재 인증 사용자)
|
||||
* @return TemplateLayoutVersion 생성된 버전
|
||||
*/
|
||||
public function saveVersion(int $layoutId, array $content, ?array $previousContent = null): TemplateLayoutVersion
|
||||
public function saveVersion(int $layoutId, array $content, ?array $previousContent = null, ?int $createdBy = null): TemplateLayoutVersion
|
||||
{
|
||||
$nextVersion = $this->getNextVersion($layoutId);
|
||||
|
||||
@@ -44,6 +46,8 @@ class LayoutVersionRepository implements LayoutVersionRepositoryInterface
|
||||
'version' => $nextVersion,
|
||||
'content' => $content,
|
||||
'changes_summary' => $changesSummary,
|
||||
// 저장자 — 버전 목록의 「저장자」 표시 근거. 종전엔 기록하지 않아 항상 「알 수 없음」이었다.
|
||||
'created_by' => $createdBy ?? Auth::id(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -109,9 +113,11 @@ class LayoutVersionRepository implements LayoutVersionRepositoryInterface
|
||||
$layout = TemplateLayout::findOrFail($layoutId);
|
||||
$currentContent = $layout->content;
|
||||
|
||||
// 3. 레이아웃을 복원할 content로 업데이트
|
||||
// 3. 레이아웃을 복원할 content로 업데이트 — lock_version 도 올린다. 복원 직전 화면을 열어 둔
|
||||
// 다른 편집기가 옛 lock 으로 저장하면 409 가 나야 복원 결과가 조용히 덮이지 않는다.
|
||||
$layout->update([
|
||||
'content' => $versionToRestore->content,
|
||||
'lock_version' => ((int) ($layout->lock_version ?? 0)) + 1,
|
||||
]);
|
||||
|
||||
// 4. 복원 결과를 새 버전으로 저장 — content 는 복원된 내용(versionToRestore),
|
||||
|
||||
@@ -292,13 +292,19 @@ class LayoutExtensionService
|
||||
* @param array $components 주입된 컴포넌트 배열
|
||||
* @param int $extensionId 확장 PK
|
||||
* @param LayoutExtension|null $extension 출처 라벨 부여용 확장 모델
|
||||
* @param int|null $injectionIndex overlay `injections[]` 순번 — 편집기가 저장 시 노드를 원래 injection 으로 되돌리는 열쇠. extension_point 주입은 null
|
||||
* @return array 메타가 부여된 컴포넌트 배열
|
||||
*
|
||||
* @since engine-v1.50.0
|
||||
*/
|
||||
private function markExtensionSource(array $components, int $extensionId, ?LayoutExtension $extension = null): array
|
||||
private function markExtensionSource(array $components, int $extensionId, ?LayoutExtension $extension = null, ?int $injectionIndex = null): array
|
||||
{
|
||||
return $this->applySourceMetaRecursively($components, $this->buildExtensionSourceMeta($extension, $extensionId));
|
||||
$meta = $this->buildExtensionSourceMeta($extension, $extensionId);
|
||||
if ($injectionIndex !== null) {
|
||||
$meta['injectionIndex'] = $injectionIndex;
|
||||
}
|
||||
|
||||
return $this->applySourceMetaRecursively($components, $meta);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -747,7 +753,11 @@ class LayoutExtensionService
|
||||
'injection_count' => count($injections),
|
||||
]);
|
||||
|
||||
foreach ($injections as $injection) {
|
||||
// injection 순번을 함께 순회한다 — 편집기 확장 편집 모드가 호스트 병합 트리에서 이 확장의
|
||||
// 노드를 추출해 `injections[].components` 로 되돌릴 때 어느 injection 인지 알 수 있어야
|
||||
// 한다. 순번이 메타에 없으면 재조립이 모든 노드를 버려 저장본의 injections 가 통째로
|
||||
// 비워진다(무변경 저장으로도 발생, 예외·경고 없음).
|
||||
foreach ($injections as $injectionIndex => $injection) {
|
||||
$targetId = $injection['target_id'] ?? null;
|
||||
$position = $injection['position'] ?? 'append_child';
|
||||
|
||||
@@ -785,7 +795,12 @@ class LayoutExtensionService
|
||||
// 편집 모드 출처 메타 부여 — 주입 노드와 그 자식 모두에 extension 메타
|
||||
// @since engine-v1.50.0
|
||||
if ($withSourceMeta) {
|
||||
$components = $this->markExtensionSource($components, $overlay->id, $overlay);
|
||||
$components = $this->markExtensionSource(
|
||||
$components,
|
||||
$overlay->id,
|
||||
$overlay,
|
||||
is_int($injectionIndex) ? $injectionIndex : null
|
||||
);
|
||||
}
|
||||
|
||||
$injected = $this->injectAtTarget(
|
||||
|
||||
Reference in new issue
Block a user