From e2ae1f967ede2163cbe2e32baf1bf89fa0668f81 Mon Sep 17 00:00:00 2001 From: nanguaboss <602995148@qq.com> Date: Sun, 9 Aug 2026 21:20:49 +0800 Subject: [PATCH] =?UTF-8?q?v1.0.29-fix:=20=E6=96=B0=E5=A2=9E=E5=AE=8C?= =?UTF-8?q?=E6=95=B4=E5=BA=A6=E5=85=A8=E9=87=8F=E9=87=8D=E7=AE=97=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=20tools/recalc=5Fcompleteness.php(=E5=AD=98=E9=87=8F?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=9B=9E=E5=A1=AB=20is=5Fincomplete,?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20--dry-run)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/recalc_completeness.php | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tools/recalc_completeness.php diff --git a/tools/recalc_completeness.php b/tools/recalc_completeness.php new file mode 100644 index 0000000..35f03e7 --- /dev/null +++ b/tools/recalc_completeness.php @@ -0,0 +1,63 @@ +getPdo(); +$summary = []; + +/** 逐条重算某表 */ +function recalcTable(PDO $pdo, $table, $sql, $dryRun, &$summary, $label, $realTable = null, $idCol = 'id') +{ + $realTable = $realTable ?: $table; + $rows = $pdo->query($sql)->fetchAll(PDO::FETCH_COLUMN); + $total = count($rows); + $changed = 0; + foreach ($rows as $id) { + $id = (int)$id; + if ($dryRun) { + // 只读计算,不写库 + $info = completenessInfo($pdo, $table, $id); + } else { + $info = updateIncomplete($pdo, $table, $id); + } + if ($info === null) { + continue; + } + if ($dryRun) { + $flag = $info['is_complete'] ? 0 : 1; + $cur = (int)$pdo->query("SELECT is_incomplete FROM `$realTable` WHERE `$idCol` = $id")->fetchColumn(); + if ($cur !== $flag) { + $changed++; + } + } else { + $changed++; + } + } + $summary[$label] = ['total' => $total, 'changed' => $changed]; +} + +echo $dryRun ? "[DRY-RUN] 仅统计,不写库\n" : "开始全量重算完整度标记...\n"; + +recalcTable($pdo, 'persons', "SELECT id FROM persons", $dryRun, $summary, 'persons'); +recalcTable($pdo, 'companies', "SELECT id FROM companies", $dryRun, $summary, 'companies'); +recalcTable($pdo, 'social_accounts', "SELECT id FROM social_accounts", $dryRun, $summary, 'social_accounts'); +recalcTable($pdo, 'media', "SELECT social_account_id FROM media_commercial_attributes", $dryRun, $summary, 'media', 'media_commercial_attributes', 'social_account_id'); + +foreach ($summary as $label => $s) { + printf("%-16s 共 %d 条,%s %d 条\n", $label, $s['total'], $dryRun ? '将被更新' : '已更新', $s['changed']); +} + +$softTotal = 0; +foreach (['companies', 'persons', 'social_accounts', 'media_commercial_attributes'] as $t) { + $softTotal += (int)$pdo->query("SELECT COUNT(*) FROM `$t` WHERE is_incomplete = 1")->fetchColumn(); +} +echo "重算后软碎片总数:{$softTotal}\n";