From 57b9cdf59ba943d080154fd90c22fc29ca84713e Mon Sep 17 00:00:00 2001 From: ddCat <2695092045@qq.com> Date: Thu, 6 Aug 2026 12:24:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(database):=20=E6=96=87=E6=9C=AC=E5=9B=9E?= =?UTF-8?q?=E6=94=BE=20-=20=E7=BB=9F=E4=B8=80=E5=A2=9E=E9=87=8F=E8=A1=A8?= =?UTF-8?q?=E5=90=8D=E5=B9=B6=E8=A1=A5=E9=BD=90=E8=B7=A8=E5=BA=93=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E6=B8=85=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/cmd/migrate-sqlite-postgres/main.go | 1 + backend/internal/repository/repository.go | 2 +- backend/internal/repository/text_replay.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/cmd/migrate-sqlite-postgres/main.go b/backend/cmd/migrate-sqlite-postgres/main.go index b6859e0f2..c5b93b487 100644 --- a/backend/cmd/migrate-sqlite-postgres/main.go +++ b/backend/cmd/migrate-sqlite-postgres/main.go @@ -243,6 +243,7 @@ func migrations() []tableMigration { migrateTable[model.Announcement]("announcements"), migrateTable[model.UserAnnouncementRead]("user_announcement_reads"), migrateTable[model.Task]("tasks"), + migrateTable[model.TaskTextDelta]("task_text_delta"), migrateTable[model.Session]("sessions"), migrateTable[model.Message]("messages"), migrateTable[model.TaskLog]("task_logs"), diff --git a/backend/internal/repository/repository.go b/backend/internal/repository/repository.go index ba19e1c1c..71cf8defc 100644 --- a/backend/internal/repository/repository.go +++ b/backend/internal/repository/repository.go @@ -63,7 +63,7 @@ func (r *Repository) UserStorageUsage(userID string) (UserStorageUsage, error) { (SELECT COALESCE(SUM(length(CAST(COALESCE(prompt, '') AS BLOB)) + length(CAST(COALESCE(input_json, '') AS BLOB)) + length(CAST(COALESCE(result_json, '') AS BLOB)) + length(CAST(COALESCE(text_draft, '') AS BLOB)) + length(CAST(COALESCE(error, '') AS BLOB))), 0) FROM tasks WHERE user_id = ?) + (SELECT COALESCE(SUM(length(CAST(COALESCE(message, '') AS BLOB)) + length(CAST(COALESCE(payload, '') AS BLOB))), 0) FROM task_logs WHERE user_id = ?) + (SELECT COALESCE(SUM(length(CAST(COALESCE(url, '') AS BLOB)) + length(CAST(COALESCE(payload, '') AS BLOB))), 0) FROM results WHERE user_id = ?) - + (SELECT COALESCE(SUM(byte_count), 0) FROM task_text_deltas WHERE user_id = ?) + + (SELECT COALESCE(SUM(byte_count), 0) FROM task_text_delta WHERE user_id = ?) + (SELECT COALESCE(SUM(length(CAST(COALESCE(path, '') AS BLOB)) + length(CAST(COALESCE(model, '') AS BLOB)) + length(CAST(COALESCE(provider_request_id, '') AS BLOB)) + length(CAST(COALESCE(error_code, '') AS BLOB)) + length(CAST(COALESCE(error, '') AS BLOB)) + length(CAST(COALESCE(upstream_url, '') AS BLOB)) + length(CAST(COALESCE(request_body, '') AS BLOB)) + length(CAST(COALESCE(response_body, '') AS BLOB))), 0) FROM api_call_logs WHERE user_id = ?) AS task_bytes, (SELECT COUNT(*) FROM api_call_logs WHERE user_id = ?) AS api_call_count ` diff --git a/backend/internal/repository/text_replay.go b/backend/internal/repository/text_replay.go index c93bcdf5b..26b51c7b0 100644 --- a/backend/internal/repository/text_replay.go +++ b/backend/internal/repository/text_replay.go @@ -117,7 +117,7 @@ func (r *Repository) CleanupTaskTextDeltas(now time.Time) (int64, error) { return err } } - result := tx.Where("expires_at <= ? OR NOT EXISTS (SELECT 1 FROM tasks WHERE tasks.id = task_text_deltas.task_id)", now).Delete(&model.TaskTextDelta{}) + result := tx.Where("expires_at <= ? OR NOT EXISTS (SELECT 1 FROM tasks WHERE tasks.id = task_text_delta.task_id)", now).Delete(&model.TaskTextDelta{}) deleted = result.RowsAffected return result.Error })