更新高密度浏览模式

This commit is contained in:
MasonLiu committed 2026-05-31 14:00:27 +08:00
1 parent 529ad70e11
commit e58195147f
15 files changed
+1184 -107

No files matched your search

+38
View File
@@ -8,6 +8,7 @@ class SecHubDatabase {
private $dbPath;
private $jsonDir;
private $db;
private $needsInitialSync = false;
public function __construct($dbPath, $jsonDir) {
$this->dbPath = $dbPath;
@@ -20,18 +21,43 @@ class SecHubDatabase {
*/
private function initDatabase() {
try {
// 检查数据库文件是否存在
$dbExists = file_exists($this->dbPath);
$this->db = new PDO('sqlite:' . $this->dbPath);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
// 创建同步日志表
$this->createSyncLogTable();
// 如果数据库文件是新创建的,或者没有任何业务数据表,标记需要同步
if (!$dbExists || $this->isEmptyDatabase()) {
$this->needsInitialSync = true;
}
} catch (PDOException $e) {
error_log("数据库连接失败: " . $e->getMessage());
throw $e;
}
}
/**
* 检查数据库是否为空(没有业务数据表)
*/
private function isEmptyDatabase() {
try {
$sql = "SELECT count(*) as table_count FROM sqlite_master
WHERE type='table'
AND name NOT LIKE 'sqlite_%'
AND name != 'json_sync_log'";
$stmt = $this->db->query($sql);
$result = $stmt->fetch();
return $result['table_count'] == 0;
} catch (Exception $e) {
return true;
}
}
/**
* 创建同步日志表
*/
@@ -52,6 +78,18 @@ class SecHubDatabase {
* 检查并同步JSON数据到数据库
*/
public function syncJsonToDatabase() {
// 如果是初始同步,强制同步所有文件
if ($this->needsInitialSync) {
$jsonFiles = glob($this->jsonDir . '*.json');
foreach ($jsonFiles as $file) {
$this->syncSingleFile($file);
}
$this->needsInitialSync = false;
return;
}
// 正常增量同步
$jsonFiles = glob($this->jsonDir . '*.json');
foreach ($jsonFiles as $file) {