fix: avoid history reclamation during structure-only upgrades
Ordinary database schema upgrades previously ran VACUUM on free pages and showed misleading history-cleanup progress. Separate structure upgrades from required legacy conversions, retaining reclamation intent only for retries within the same startup. Preserve released data without new schema versions or persistent migration markers; Agent and normal writes remain unchanged. Add real SQLite and Worker regressions, bilingual operation-specific startup copy, and migration documentation. Synchronize native Electron drag input with actual resize state without weakening layout assertions. Validation: 47 focused migration tests passed; typecheck, lint and diff checks passed. Final full suite: 5137 passed, 74 skipped, 2 unrelated Electron failures. Both failing Electron tests passed an isolated rerun; full CI remains unverified. Release note: 修复普通数据库结构升级再次整理历史和回收空间的问题;仅在需要转换旧数据时执行相关处理,启动页准确显示当前升级操作。
This commit is contained in:
@@ -10,7 +10,7 @@ import {
|
||||
} from '../shared/assistant-storage-contracts'
|
||||
import { ipcChannels } from '../shared/ipc-channels'
|
||||
import { assertTrustedSender } from './trusted-ipc-sender'
|
||||
import { hasPendingAssistantStorageUpgrade } from './assistant/assistant-storage-upgrade'
|
||||
import { getPendingAssistantStorageUpgrade, type AssistantStorageUpgrade } from './assistant/assistant-storage-upgrade'
|
||||
import { loadMainWindow } from './window'
|
||||
|
||||
export async function prepareAssistantStorage(
|
||||
@@ -23,9 +23,10 @@ export async function prepareAssistantStorage(
|
||||
throw error
|
||||
})
|
||||
if (!file) return
|
||||
if (!hasPendingAssistantStorageUpgrade(databasePath)) return
|
||||
const upgrade = getPendingAssistantStorageUpgrade(databasePath)
|
||||
if (!upgrade) return
|
||||
let progress: AssistantStorageProgress = {
|
||||
stage: 'scanning', processed: 0, total: 0, bytesBefore: file.size
|
||||
stage: 'upgrading', processed: 0, total: 0, bytesBefore: file.size
|
||||
}
|
||||
let shown = false
|
||||
let retry: (() => void) | undefined
|
||||
@@ -53,13 +54,13 @@ export async function prepareAssistantStorage(
|
||||
try {
|
||||
while (!signal.aborted) {
|
||||
try {
|
||||
await runStorageWorker(databasePath, signal, publish)
|
||||
await runStorageWorker(databasePath, upgrade, signal, publish)
|
||||
return
|
||||
} catch (error) {
|
||||
if (signal.aborted) return
|
||||
publish({
|
||||
...progress, stage: 'failed',
|
||||
error: error instanceof Error ? error.message : '历史执行记录优化失败'
|
||||
error: error instanceof Error ? error.message : '本地数据升级失败'
|
||||
})
|
||||
await new Promise<void>((resolve) => {
|
||||
const finish = (): void => {
|
||||
@@ -81,6 +82,7 @@ export async function prepareAssistantStorage(
|
||||
|
||||
function runStorageWorker(
|
||||
databasePath: string,
|
||||
upgrade: AssistantStorageUpgrade,
|
||||
signal: AbortSignal,
|
||||
publish: (progress: AssistantStorageProgress) => void
|
||||
): Promise<void> {
|
||||
@@ -93,7 +95,7 @@ function runStorageWorker(
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const worker = new Worker(join(
|
||||
dirname(fileURLToPath(import.meta.url)), 'assistant-storage-worker.js'
|
||||
), { workerData: { databasePath, cancellation } })
|
||||
), { workerData: { databasePath, cancellation, upgrade } })
|
||||
let failure: Error | undefined
|
||||
let done = false
|
||||
worker.on('message', (message: {
|
||||
@@ -107,13 +109,13 @@ function runStorageWorker(
|
||||
if (message.done || message.cancelled) done = true
|
||||
})
|
||||
worker.once('error', () => {
|
||||
failure = new Error('无法启动历史执行记录优化,请重启 GoodBuddy 后重试。')
|
||||
failure = new Error('无法启动本地数据升级,请重启 GoodBuddy 后重试。')
|
||||
})
|
||||
worker.once('exit', (code) => {
|
||||
signal.removeEventListener('abort', cancel)
|
||||
if (failure) reject(failure)
|
||||
else if (done && code === 0) resolve()
|
||||
else reject(new Error('历史执行记录优化意外结束,请重试。'))
|
||||
else reject(new Error('本地数据升级意外结束,请重试。'))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user