fix(core,admin_basic,board,ecommerce,page,gdpr,verification): 설정 미러·자동 정리·탈퇴 원자성·일괄 선택 범위 정비
공개이슈 ··· 및 그 전수 해소분. - 설정 저장·복원·초기화가 상주 프로세스 미러를 갱신하도록 단일 소유자화 - 만료 데이터 자동 정리 예약 12종 신설, 파기는 기본키 배치로 분할 - 회원 탈퇴를 전 경로 원자화하고 관리자 상태변경 경로를 정식 탈퇴로 통일 - 일괄 처리 목록의 선택을 화면에 보이는 행으로 한정(selectionScope) - 비밀번호 정책 문구를 도메인 중립 라벨로 정정 - 정적 검사 2종·검증 스킬 설계 정합성 축 신설
This commit is contained in:
1 parent
49c155509e
commit
4e1ec6e001
136 files changed
+7016
-504
No files matched your search
@@ -7,6 +7,7 @@ use App\Helpers\PermissionHelper;
|
||||
use App\Helpers\TimezoneHelper;
|
||||
use App\Http\Resources\BaseApiCollection;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Repositories\Concerns\DeletesInBatches;
|
||||
use App\Repositories\Concerns\HasMultipleSearchFilters;
|
||||
use App\Repositories\Concerns\PaginatesWithDeferredJoin;
|
||||
use App\Repositories\Concerns\ResolvesSortSpec;
|
||||
@@ -23,6 +24,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
*/
|
||||
class ActivityLogRepository implements ActivityLogRepositoryInterface
|
||||
{
|
||||
use DeletesInBatches;
|
||||
use HasMultipleSearchFilters;
|
||||
use PaginatesWithDeferredJoin;
|
||||
use ResolvesSortSpec;
|
||||
@@ -316,4 +318,20 @@ class ActivityLogRepository implements ActivityLogRepositoryInterface
|
||||
{
|
||||
return ActivityLog::where('user_id', $userId)->update(['user_id' => null]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 보존 기간이 지난 활동 로그를 삭제합니다.
|
||||
*
|
||||
* 보존 기간 하한(1일)은 이 계층이 소유한다 — 파기는 되돌릴 수 없으므로 호출자마다
|
||||
* 다시 막지 않고 실제로 지우는 자리에서 한 번 막는다.
|
||||
*
|
||||
* @param int $days 보존 기간 (일)
|
||||
* @return int 삭제된 건수
|
||||
*/
|
||||
public function deleteOlderThan(int $days): int
|
||||
{
|
||||
return $this->deleteInBatches(
|
||||
ActivityLog::where('created_at', '<', now()->subDays(max(1, $days)))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Concerns;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* 보존 기간 초과 행을 배치로 나눠 삭제하는 트레이트
|
||||
*
|
||||
* 정리 예약은 도입 직후 첫 실행에서 이미 쌓여 있던 과거 데이터를 전부 지운다.
|
||||
* 수년치가 한 문장으로 삭제되면 그 한 건이 테이블을 오래 잠그고, 트랜잭션 로그도
|
||||
* 그만큼 부풀어 정리 배치가 사이트를 멈추게 한다 — 정리하려던 문제를 정리 작업이
|
||||
* 다시 만드는 셈이다.
|
||||
*
|
||||
* 그래서 기본키 배치로 끊어 지운다. 각 DELETE 는 최대 batchSize 건의 기본키 IN 절이라
|
||||
* 잠금 구간이 짧고, 중간에 중단돼도 이미 지운 만큼은 확정된다(정리는 멱등이라
|
||||
* 다음 실행이 남은 몫을 이어서 처리한다).
|
||||
*/
|
||||
trait DeletesInBatches
|
||||
{
|
||||
/**
|
||||
* 기본 배치 크기
|
||||
*/
|
||||
protected int $deleteBatchSize = 1000;
|
||||
|
||||
/**
|
||||
* 조건에 맞는 행을 배치로 나눠 삭제합니다.
|
||||
*
|
||||
* 기본키를 먼저 모아 그 키로만 지운다 — `DELETE ... LIMIT` 은 드라이버마다 지원이
|
||||
* 갈리지만 기본키 IN 절은 어디서나 같게 동작한다.
|
||||
*
|
||||
* @param Builder $query 삭제 대상 조건이 적용된 쿼리 (정렬·제한 미적용 상태)
|
||||
* @param int|null $batchSize 배치 크기 (미지정 시 $deleteBatchSize)
|
||||
* @return int 삭제된 총 건수
|
||||
*/
|
||||
protected function deleteInBatches(Builder $query, ?int $batchSize = null): int
|
||||
{
|
||||
$batchSize = max(1, $batchSize ?? $this->deleteBatchSize);
|
||||
$model = $query->getModel();
|
||||
$keyName = $model->getKeyName();
|
||||
$total = 0;
|
||||
|
||||
while (true) {
|
||||
// audit:allow query-repeated-execution 배치 삭제는 같은 술어를 의도적으로 반복 평가한다 — 매 회차의 모집단이 직전 삭제로 줄어든다
|
||||
$keys = (clone $query)->orderBy($keyName)->limit($batchSize)->pluck($keyName);
|
||||
|
||||
if ($keys->isEmpty()) {
|
||||
return $total;
|
||||
}
|
||||
|
||||
$total += $model->newQuery()->whereIn($keyName, $keys)->delete();
|
||||
|
||||
// 마지막 배치 — 더 조회할 것이 없다
|
||||
if ($keys->count() < $batchSize) {
|
||||
return $total;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use App\Enums\IdentityVerificationStatus;
|
||||
use App\Helpers\TimezoneHelper;
|
||||
use App\Models\IdentityPolicy;
|
||||
use App\Models\IdentityVerificationLog;
|
||||
use App\Repositories\Concerns\DeletesInBatches;
|
||||
use App\Repositories\Concerns\PaginatesWithDeferredJoin;
|
||||
use App\Support\Query\PaginationLimits;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
@@ -19,6 +20,7 @@ use Illuminate\Support\Carbon;
|
||||
*/
|
||||
class IdentityVerificationLogRepository implements IdentityVerificationLogRepositoryInterface
|
||||
{
|
||||
use DeletesInBatches;
|
||||
use PaginatesWithDeferredJoin;
|
||||
|
||||
/**
|
||||
@@ -127,9 +129,10 @@ class IdentityVerificationLogRepository implements IdentityVerificationLogReposi
|
||||
*/
|
||||
public function purgeOlderThan(int $days): int
|
||||
{
|
||||
return IdentityVerificationLog::query()
|
||||
->where('created_at', '<', Carbon::now()->subDays(max(1, $days)))
|
||||
->delete();
|
||||
return $this->deleteInBatches(
|
||||
IdentityVerificationLog::query()
|
||||
->where('created_at', '<', Carbon::now()->subDays(max(1, $days)))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Contracts\Repositories\NotificationLogRepositoryInterface;
|
||||
use App\Enums\NotificationLogStatus;
|
||||
use App\Models\NotificationLog;
|
||||
use App\Models\User;
|
||||
use App\Repositories\Concerns\DeletesInBatches;
|
||||
use App\Repositories\Concerns\PaginatesWithDeferredJoin;
|
||||
use App\Repositories\Concerns\ResolvesSortSpec;
|
||||
use App\Support\Query\KeysetPaginator;
|
||||
@@ -17,6 +18,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
class NotificationLogRepository implements NotificationLogRepositoryInterface
|
||||
{
|
||||
use DeletesInBatches;
|
||||
use PaginatesWithDeferredJoin;
|
||||
use ResolvesSortSpec;
|
||||
|
||||
@@ -98,6 +100,22 @@ class NotificationLogRepository implements NotificationLogRepositoryInterface
|
||||
return NotificationLog::whereIn('id', $ids)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 보존 기간이 지난 발송 이력을 삭제합니다.
|
||||
*
|
||||
* 보존 기간 하한(1일)은 이 계층이 소유한다 — 파기는 되돌릴 수 없으므로 호출자마다
|
||||
* 다시 막지 않고 실제로 지우는 자리에서 한 번 막는다.
|
||||
*
|
||||
* @param int $days 보존 기간 (일)
|
||||
* @return int 삭제된 건수
|
||||
*/
|
||||
public function deleteOlderThan(int $days): int
|
||||
{
|
||||
return $this->deleteInBatches(
|
||||
NotificationLog::where('created_at', '<', now()->subDays(max(1, $days)))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 페이지네이션 목록 조회.
|
||||
*
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Repositories;
|
||||
|
||||
use App\Contracts\Repositories\ScheduleHistoryRepositoryInterface;
|
||||
use App\Models\ScheduleHistory;
|
||||
use App\Repositories\Concerns\DeletesInBatches;
|
||||
use App\Repositories\Concerns\PaginatesWithDeferredJoin;
|
||||
use App\Repositories\Concerns\ResolvesSortSpec;
|
||||
use App\Support\Query\PaginationLimits;
|
||||
@@ -13,6 +14,7 @@ use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class ScheduleHistoryRepository implements ScheduleHistoryRepositoryInterface
|
||||
{
|
||||
use DeletesInBatches;
|
||||
use PaginatesWithDeferredJoin;
|
||||
use ResolvesSortSpec;
|
||||
|
||||
@@ -169,6 +171,10 @@ class ScheduleHistoryRepository implements ScheduleHistoryRepositoryInterface
|
||||
*/
|
||||
public function deleteOlderThan(int $days): int
|
||||
{
|
||||
return ScheduleHistory::where('started_at', '<', now()->subDays($days))->delete();
|
||||
// 보존 기간 하한(1일)은 이 계층이 소유한다 — 파기는 되돌릴 수 없으므로
|
||||
// 호출자마다 다시 막지 않고 실제로 지우는 자리에서 한 번 막는다.
|
||||
return $this->deleteInBatches(
|
||||
ScheduleHistory::where('started_at', '<', now()->subDays(max(1, $days)))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Repositories;
|
||||
|
||||
use App\Contracts\Repositories\SeoCacheStatRepositoryInterface;
|
||||
use App\Models\SeoCacheStat;
|
||||
use App\Repositories\Concerns\DeletesInBatches;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Database\Query\Expression;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
@@ -16,6 +17,8 @@ use Illuminate\Support\Facades\DB;
|
||||
*/
|
||||
class SeoCacheStatRepository implements SeoCacheStatRepositoryInterface
|
||||
{
|
||||
use DeletesInBatches;
|
||||
|
||||
/**
|
||||
* 그룹 집계에 허용된 컬럼 목록
|
||||
*
|
||||
@@ -96,7 +99,7 @@ class SeoCacheStatRepository implements SeoCacheStatRepositoryInterface
|
||||
*/
|
||||
public function deleteOlderThan(Carbon $cutoff): int
|
||||
{
|
||||
return SeoCacheStat::where('created_at', '<', $cutoff)->delete();
|
||||
return $this->deleteInBatches(SeoCacheStat::where('created_at', '<', $cutoff));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user