매 요청 균일하게 발생하던 부팅 오버헤드를 4개 축에서 제거한다. - 설치 완료 상태에서 매 요청 반복되던 information_schema 조회(알림·본인인증 테이블 hasTable)를 installer_completed 가드로 스킵. 미설치 환경은 기존 hasTable 폴백 유지. - 코어+모듈+플러그인 정적 훅 매핑을 bootstrap/cache/hooks.php 에 사전 계산해 매 요청 디렉토리 스캔·리플렉션·클래스 로딩을 제거(route:cache 동형). 등록↔발화 계약·매핑 바이트 동일. 확장/코어 변경 시 자동 재생성, 캐시 부재·손상은 스캔 폴백. - 확장 소스(Modules\*/Plugins\*)를 autoload-extensions.php 의 classmap 에 편입해 findFile 파일시스템 스캔을 제거(느린 FS·cold OPcache 환경 직격). 클래스 로딩은 여전히 lazy, PSR-4 폴백 유지. - config 캐시를 변경 지점(설정 저장/코어·확장 업데이트/APP_KEY 재생성/설치 완료)에서 clear 후 즉시 재생성하도록 ConfigCacheHelper 로 일원화. clear 만 하고 방치돼 캐시가 영구 비활성으로 남던 성능 손실 제거. HookCacheManager::read 요청당 1회 로드(memo)로 중복 파싱 제거. 부팅 매핑 fingerprint 스캔↔캐시 완전 동일(229 action + 35 filter). 신규/수정 8개 스위트 54 pass. 순수 내부 부팅 인프라 — 확장 공개 표면·훅 계약 불변.
191 lines
7.0 KiB
PHP
191 lines
7.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Extension;
|
|
|
|
use App\Contracts\Repositories\IdentityPolicyRepositoryInterface;
|
|
use App\Extension\ModuleManager;
|
|
use App\Extension\PluginManager;
|
|
use App\Extension\TemplateManager;
|
|
use App\Listeners\NotificationHookListener;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* `config('app.installer_completed')` 가드가 Schema::hasTable() 호출을
|
|
* 건너뛰는지 검증합니다.
|
|
*
|
|
* 성능 회귀 방지 목적: 설치 완료 상태에서 매 요청 `information_schema.tables`
|
|
* 쿼리가 실행되지 않아야 합니다.
|
|
*/
|
|
class InstallerCompletedGuardTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
config(['app.installer_completed' => false]);
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**
|
|
* 주어진 콜백 실행 중 발생한 information_schema.tables 쿼리만 수집합니다.
|
|
*
|
|
* @param callable $callback 계측할 코드
|
|
* @return array<int, array<string, mixed>> information_schema.tables 쿼리 목록
|
|
*/
|
|
private function captureSchemaTableQueries(callable $callback): array
|
|
{
|
|
DB::enableQueryLog();
|
|
$callback();
|
|
$queries = DB::getQueryLog();
|
|
DB::disableQueryLog();
|
|
|
|
return array_filter(
|
|
$queries,
|
|
fn ($q) => str_contains($q['query'], 'information_schema.tables')
|
|
);
|
|
}
|
|
|
|
public function test_module_trait_skips_has_table_when_installer_completed(): void
|
|
{
|
|
config(['app.installer_completed' => true]);
|
|
|
|
$schemaQueries = $this->captureSchemaTableQueries(
|
|
fn () => ModuleManager::getActiveModuleIdentifiers()
|
|
);
|
|
|
|
$this->assertCount(0, $schemaQueries, 'installer_completed=true 에서는 information_schema.tables 쿼리가 발생하지 않아야 합니다');
|
|
}
|
|
|
|
public function test_plugin_trait_skips_has_table_when_installer_completed(): void
|
|
{
|
|
config(['app.installer_completed' => true]);
|
|
|
|
$schemaQueries = $this->captureSchemaTableQueries(
|
|
fn () => PluginManager::getActivePluginIdentifiers()
|
|
);
|
|
|
|
$this->assertCount(0, $schemaQueries);
|
|
}
|
|
|
|
public function test_template_trait_skips_has_table_when_installer_completed(): void
|
|
{
|
|
config(['app.installer_completed' => true]);
|
|
|
|
$schemaQueries = $this->captureSchemaTableQueries(
|
|
fn () => TemplateManager::getActiveTemplateIdentifiers()
|
|
);
|
|
|
|
$this->assertCount(0, $schemaQueries);
|
|
}
|
|
|
|
public function test_module_trait_falls_back_to_has_table_when_installer_not_completed(): void
|
|
{
|
|
config(['app.installer_completed' => false]);
|
|
|
|
$schemaQueries = $this->captureSchemaTableQueries(
|
|
fn () => ModuleManager::getActiveModuleIdentifiers()
|
|
);
|
|
|
|
$this->assertGreaterThan(0, count($schemaQueries), 'installer_completed=false 에서는 기존 hasTable 경로가 실행되어야 합니다');
|
|
}
|
|
|
|
/**
|
|
* NotificationHookListener::registerDynamicHooks() 의 hasTable 가드 검증.
|
|
*
|
|
* 부팅 시점 동적 훅 등록 경로 — 설치 완료 상태에서 매 요청
|
|
* `information_schema.tables` 조회(notification_definitions)가 사라져야 합니다.
|
|
*/
|
|
public function test_notification_listener_skips_has_table_when_installer_completed(): void
|
|
{
|
|
config(['app.installer_completed' => true]);
|
|
|
|
$listener = app(NotificationHookListener::class);
|
|
|
|
$schemaQueries = $this->captureSchemaTableQueries(
|
|
fn () => $listener->registerDynamicHooks()
|
|
);
|
|
|
|
$this->assertCount(0, $schemaQueries, 'installer_completed=true 에서는 notification_definitions hasTable 조회가 발생하지 않아야 합니다');
|
|
}
|
|
|
|
public function test_notification_listener_falls_back_to_has_table_when_installer_not_completed(): void
|
|
{
|
|
config(['app.installer_completed' => false]);
|
|
|
|
$listener = app(NotificationHookListener::class);
|
|
|
|
$schemaQueries = $this->captureSchemaTableQueries(
|
|
fn () => $listener->registerDynamicHooks()
|
|
);
|
|
|
|
$this->assertGreaterThan(0, count($schemaQueries), 'installer_completed=false 에서는 기존 hasTable 경로가 실행되어야 합니다');
|
|
}
|
|
|
|
/**
|
|
* IdentityPolicyRepository::listHookTargets() 의 hasTable 가드 검증.
|
|
*
|
|
* 부팅 시점 IDV 동적 hook target 동기화 경로 — 설치 완료 상태에서
|
|
* `information_schema.tables` 조회(identity_policies)가 사라져야 합니다.
|
|
*/
|
|
public function test_identity_policy_list_hook_targets_skips_has_table_when_installer_completed(): void
|
|
{
|
|
config(['app.installer_completed' => true]);
|
|
|
|
$repository = app(IdentityPolicyRepositoryInterface::class);
|
|
|
|
$schemaQueries = $this->captureSchemaTableQueries(
|
|
fn () => $repository->listHookTargets()
|
|
);
|
|
|
|
$this->assertCount(0, $schemaQueries, 'installer_completed=true 에서는 identity_policies hasTable 조회가 발생하지 않아야 합니다');
|
|
}
|
|
|
|
public function test_identity_policy_list_hook_targets_falls_back_when_installer_not_completed(): void
|
|
{
|
|
config(['app.installer_completed' => false]);
|
|
|
|
$repository = app(IdentityPolicyRepositoryInterface::class);
|
|
|
|
$schemaQueries = $this->captureSchemaTableQueries(
|
|
fn () => $repository->listHookTargets()
|
|
);
|
|
|
|
$this->assertGreaterThan(0, count($schemaQueries), 'installer_completed=false 에서는 기존 hasTable 경로가 실행되어야 합니다');
|
|
}
|
|
|
|
/**
|
|
* IdentityPolicyRepository::activeExtensionIdentifiers() 의 hasTable 가드 검증.
|
|
*
|
|
* `resolveByScopeTarget()` → `applyActiveExtensionScope()` → `activeExtensionIdentifiers()`
|
|
* 경로로 modules/plugins 테이블 hasTable 조회가 트리거되며, 설치 완료 상태에서는
|
|
* 해당 `information_schema.tables` 조회가 사라져야 합니다.
|
|
*/
|
|
public function test_active_extension_scope_skips_has_table_when_installer_completed(): void
|
|
{
|
|
config(['app.installer_completed' => true]);
|
|
|
|
$repository = app(IdentityPolicyRepositoryInterface::class);
|
|
|
|
$schemaQueries = $this->captureSchemaTableQueries(
|
|
fn () => $repository->resolveByScopeTarget('hook', 'core.auth.signup_before_submit')
|
|
);
|
|
|
|
$this->assertCount(0, $schemaQueries, 'installer_completed=true 에서는 modules/plugins hasTable 조회가 발생하지 않아야 합니다');
|
|
}
|
|
|
|
public function test_active_extension_scope_falls_back_when_installer_not_completed(): void
|
|
{
|
|
config(['app.installer_completed' => false]);
|
|
|
|
$repository = app(IdentityPolicyRepositoryInterface::class);
|
|
|
|
$schemaQueries = $this->captureSchemaTableQueries(
|
|
fn () => $repository->resolveByScopeTarget('hook', 'core.auth.signup_before_submit')
|
|
);
|
|
|
|
$this->assertGreaterThan(0, count($schemaQueries), 'installer_completed=false 에서는 기존 hasTable 경로가 실행되어야 합니다');
|
|
}
|
|
}
|