Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .monkeycode/specs/db-batch-optimization/tasklist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 数据库批量操作优化实施计划

- [x] 1. 实现 collectCurrentRuntimeStateSnapshot() 分页加载优化
- [x] 1.1 创建分页查询工具函数
- 在 backupService.ts 中实现 batchQueryAll(db, table, batchSize) 工具函数
- 每次查询最多返回 batchSize 条记录,支持游标分页
- [x] 1.2 重构 proxyLogs 分页加载
- 将 `db.select().from(schema.proxyLogs).all()` 改为分页加载
- 按 id 升序分页,每次最多 10 条,循环直到加载完全部数据
- 使用累积变量收集所有 proxyLogs 数据
- [x] 1.3 重构其他大表分页加载
- 对 checkinLogs 表实现相同分页策略

- [x] 2. 实现 importAccountsSection() 分批插入优化
- [x] 2.1 创建分批插入工具函数
- 实现 batchInsertHelper(tx, table, records, batchSize) 工具函数
- 每批最多插入 10 条记录,循环直到完成
- [x] 2.2 重构 sites 表分批插入
- 将 for 循环插入改为 batchInsertHelper 分批执行
- [x] 2.3 重构 siteApiEndpoints 表分批插入
- 将 for 循环插入改为 batchInsertHelper 分批执行
- [x] 2.4 重构 accounts 表分批插入
- 将 for 循环插入改为 batchInsertHelper 分批执行
- [x] 2.5 重构 accountTokens 表分批插入
- 将 for 循环插入改为 batchInsertHelper 分批执行
- [x] 2.6 重构 tokenRoutes 表分批插入
- 将 for 循环插入改为 batchInsertHelper 分批执行
- [x] 2.7 重构 routeChannels 表分批插入
- 将 for 循环插入改为 batchInsertHelper 分批执行
- [x] 2.8 重构 routeGroupSources 表分批插入
- 将 for 循环插入改为 batchInsertHelper 分批执行
- [x] 2.9 重构 modelAvailability 表分批插入
- 将 for 循环插入改为 batchInsertHelper 分批执行
- [x] 2.10 重构 tokenModelAvailability 表分批插入
- 将 for 循环插入改为 batchInsertHelper 分批执行
- [x] 2.11 重构 siteDisabledModels 表分批插入
- 将 for 循环插入改为 batchInsertHelper 分批执行
- [x] 2.12 重构 siteAnnouncements 表分批插入
- 将 for 循环改为批量收集记录后使用 batchInsertHelper 分批执行
- [x] 2.13 重构 proxyLogs 表分批插入
- 将 for 循环改为批量收集记录后使用 batchInsertHelper 分批执行
- [x] 2.14 重构 checkinLogs 表分批插入
- 将 for 循环改为批量收集记录后使用 batchInsertHelper 分批执行

- [x] 3. 检查点 - 确保代码编译通过
- 运行 TypeScript 编译检查
- 确保没有语法错误

- [x] 4. 编写单元测试
- [x] 4.1 为 batchQueryAll 编写单元测试
- [x] 4.2 为 batchInsertHelper 编写单元测试
12 changes: 12 additions & 0 deletions .trae/specs/database-timeout-optimization/checklist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Database and Gateway Timeout Optimization - Verification Checklist

- [x] Database connection timeout configuration is set to at least 300 seconds
- [x] Large data import timeout settings are appropriate for long-running operations
- [x] Gateway service timeout settings match or exceed database operation timeouts
- [x] Complex database operations complete successfully without timeout errors
- [x] No timeout errors occur during large data import operations
- [x] All timeout settings are consistent across database, application, and gateway layers
- [x] Documentation is updated with database and gateway timeout configuration best practices
- [x] Test scenarios are created for large database operations
- [x] Database connection pool settings are reviewed and adjusted if necessary
- [x] Gateway service routing settings are reviewed and adjusted if necessary
84 changes: 84 additions & 0 deletions .trae/specs/database-timeout-optimization/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Database and Gateway Timeout Optimization - Product Requirement Document

## Overview
- **Summary**: This project aims to optimize timeout settings for database connections, large data imports, and gateway services to address timeout issues during database operations and large data processing.
- **Purpose**: To resolve timeout problems that occur during database operations, large data imports, and gateway service interactions by ensuring appropriate timeout settings across all relevant components.
- **Target Users**: System administrators, developers, and end users who interact with the application, especially those performing database operations and large data imports.

## Goals
- Optimize database connection timeout settings to handle long-running database operations
- Configure timeout settings for large data import operations
- Review and adjust gateway service timeout settings
- Ensure consistency in timeout settings across database, application, and gateway layers
- Provide documentation for timeout configuration best practices

## Non-Goals (Out of Scope)
- Modifying database schema or structure
- Adding new database features or capabilities
- Changing the core architecture of the application
- Optimizing database query performance (this is about timeout settings, not query optimization)

## Background & Context
- The application experiences timeout issues during database operations and large data imports
- Database connection timeouts may occur during complex queries or large transactions
- Large data imports can exceed default timeout settings
- Gateway services may have timeout settings that don't align with database operation requirements
- The backup import operation has been optimized with batch processing, but still requires sufficient timeout settings

## Functional Requirements
- **FR-1**: Update database connection timeout settings to handle long-running database operations
- **FR-2**: Configure timeout settings for large data import operations
- **FR-3**: Review and adjust gateway service timeout settings
- **FR-4**: Test timeout settings with large database operations

## Non-Functional Requirements
- **NFR-1**: All timeout settings should be consistent across database, application, and gateway layers
- **NFR-2**: Timeout settings should be configurable through environment variables where possible
- **NFR-3**: Documentation should be updated to include timeout configuration best practices
- **NFR-4**: Performance should not be negatively impacted by increased timeout settings

## Constraints
- **Technical**: Must maintain compatibility with existing database systems and gateway services
- **Business**: Changes should not introduce security vulnerabilities
- **Dependencies**: Must work with existing database and gateway configurations

## Assumptions
- The application uses a relational database (SQLite, MySQL, or PostgreSQL)
- Large data imports involve importing significant amounts of data that may take longer than 30 seconds
- Gateway services are used to handle external requests to the application

## Acceptance Criteria

### AC-1: Database connection timeout configuration
- **Given**: The database connection is configured with appropriate timeout settings
- **When**: A long-running database operation is initiated
- **Then**: The operation completes successfully without database connection timeout errors
- **Verification**: `programmatic`
- **Notes**: Database connection timeout should be set to at least 300 seconds

### AC-2: Large data import timeout configuration
- **Given**: Large data import operations are configured with appropriate timeout settings
- **When**: A large data import is initiated
- **Then**: The import completes successfully without timeout errors
- **Verification**: `programmatic`
- **Notes**: Import timeout should be set to handle datasets that take several minutes to process

### AC-3: Gateway service timeout configuration
- **Given**: Gateway service timeout settings are reviewed and adjusted
- **When**: Gateway services handle requests that require database operations
- **Then**: The requests complete successfully without gateway service timeouts
- **Verification**: `programmatic`
- **Notes**: Gateway timeout should be set to match or exceed database operation timeouts

### AC-4: Consistency across all layers
- **Given**: All timeout settings are configured consistently
- **When**: A complex operation involving database, application, and gateway layers is performed
- **Then**: The operation completes successfully without timeout errors at any layer
- **Verification**: `programmatic`
- **Notes**: Test with operations that take 60+ seconds to complete

## Open Questions
- [ ] What is the current database connection timeout configuration?
- [ ] What is the current gateway service timeout configuration?
- [ ] Are there any reverse proxy or load balancer timeout settings that need to be considered?
- [ ] What is the maximum expected duration for large data import operations?
67 changes: 67 additions & 0 deletions .trae/specs/database-timeout-optimization/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Database and Gateway Timeout Optimization - Implementation Plan

## [x] Task 1: Review current database connection timeout configuration
- **Priority**: P0
- **Depends On**: None
- **Description**:
- Review the current database connection timeout settings
- Identify database connection parameters related to timeouts
- Check if there are any database-specific timeout settings that need adjustment
- **Acceptance Criteria Addressed**: AC-1
- **Test Requirements**:
- `programmatic` TR-1.1: Verify database connection timeout is set to at least 300 seconds
- `programmatic` TR-1.2: Test that long-running database operations complete without connection timeouts
- **Notes**: Check database configuration files and connection pool settings

## [x] Task 2: Configure timeout settings for large data import operations
- **Priority**: P0
- **Depends On**: Task 1
- **Description**:
- Review current timeout settings for data import operations
- Adjust timeout settings for large data imports
- Ensure import operations have sufficient time to complete
- **Acceptance Criteria Addressed**: AC-2
- **Test Requirements**:
- `programmatic` TR-2.1: Verify large data import timeout settings are appropriate
- `programmatic` TR-2.2: Test large data import with dataset that takes 60+ seconds
- **Notes**: Focus on backup import and other data import operations

## [x] Task 3: Review and adjust gateway service timeout settings
- **Priority**: P0
- **Depends On**: Task 1
- **Description**:
- Review current gateway service timeout settings
- Adjust gateway service timeouts to match or exceed database operation timeouts
- Ensure gateway services can handle requests that require long-running database operations
- **Acceptance Criteria Addressed**: AC-3
- **Test Requirements**:
- `programmatic` TR-3.1: Verify gateway service timeout settings are appropriate
- `programmatic` TR-3.2: Test gateway service with requests that require long-running database operations
- **Notes**: Check gateway configuration files and routing settings

## [x] Task 4: Test timeout settings with large database operations
- **Priority**: P1
- **Depends On**: Tasks 1, 2, 3
- **Description**:
- Create test scenarios for large database operations
- Test database operations that take 60+ seconds to complete
- Verify that operations complete successfully without timeout errors
- **Acceptance Criteria Addressed**: AC-4
- **Test Requirements**:
- `programmatic` TR-4.1: Test complex database operations with large datasets
- `programmatic` TR-4.2: Verify no timeout errors occur at any layer
- **Notes**: Use realistic test data to simulate actual usage

## [x] Task 5: Update documentation for timeout configuration
- **Priority**: P2
- **Depends On**: Tasks 1, 2, 3, 4
- **Description**:
- Update project documentation to include database and gateway timeout configuration best practices
- Document database connection timeout settings
- Document gateway service timeout settings
- Provide guidance for configuring timeouts in different environments
- **Acceptance Criteria Addressed**: NFR-3
- **Test Requirements**:
- `human-judgment` TR-5.1: Documentation is clear and comprehensive
- `human-judgment` TR-5.2: Documentation covers all timeout configuration levels
- **Notes**: Update README or deployment documentation
33 changes: 33 additions & 0 deletions .trae/specs/import-issue-analysis/checklist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 导入功能问题分析 - 验证检查清单

## 代码修改检查
- [x] 检查 `coerceAccountsSection` 函数是否已修改,优化验证逻辑
- [x] 检查 `coercePreferencesSection` 函数是否已修改,优化验证逻辑
- [x] 检查 `detectAccountsSection` 函数是否已修改,确保能够正确识别各种格式的账号数据
- [x] 检查 `detectPreferencesSection` 函数是否已修改,确保能够正确识别各种格式的设置数据
- [x] 检查 `importBackup` 函数是否添加了更详细的错误信息
- [x] 检查修改后的代码是否保持向后兼容性

## 功能测试检查
- [x] 测试有效的账号数据备份文件导入
- [x] 测试有效的设置数据备份文件导入
- [x] 测试完整备份文件的导入
- [x] 测试部分数据缺失的备份文件导入
- [x] 测试旧版本备份文件的导入
- [x] 测试空数据备份文件的导入
- [x] 测试格式错误的备份文件导入

## 错误处理检查
- [x] 验证导入过程中出现错误时是否显示清晰的错误信息
- [x] 验证错误信息是否能够帮助用户理解失败原因
- [x] 验证导入功能是否能够正确处理各种边界情况和异常情况

## 性能和稳定性检查
- [x] 验证导入功能的性能是否受到影响
- [x] 验证导入功能的稳定性是否良好
- [x] 验证导入功能是否能够处理大型备份文件

## 文档和注释检查
- [x] 检查代码注释是否更新,反映修改后的逻辑
- [x] 检查是否添加了必要的文档说明
- [x] 检查是否更新了相关的测试用例
73 changes: 73 additions & 0 deletions .trae/specs/import-issue-analysis/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 导入功能问题分析 - 产品需求文档

## 概述
- **摘要**:分析并修复导入功能提示"备份导入完成:账号 未导入,设置 未导入"的问题
- **目的**:解决备份导入功能无法正确识别和处理备份文件的问题,确保账号和设置数据能够正确导入
- **目标用户**:使用备份导入功能的系统用户

## 目标
- 修复导入功能中账号数据检测和验证的问题
- 修复导入功能中设置数据检测和验证的问题
- 提高导入功能的容错性和用户体验
- 确保导入功能能够正确处理各种格式的备份文件

## 非目标(范围外)
- 不修改导出功能的逻辑
- 不改变备份文件的基本结构
- 不添加新的导入功能特性

## 背景与上下文
- 导入功能当前使用 `detectAccountsSection` 和 `detectPreferencesSection` 函数来检测备份数据中的账号和设置部分
- 当这两个函数都返回 null 时,导入功能会提示"账号 未导入,设置 未导入"
- 问题可能出现在数据检测、验证或处理逻辑中

## 功能需求
- **FR-1**:修改账号数据检测和验证逻辑,确保能够正确识别和处理各种格式的账号数据
- **FR-2**:修改设置数据检测和验证逻辑,确保能够正确识别和处理各种格式的设置数据
- **FR-3**:提供更清晰的错误信息,说明导入失败的具体原因
- **FR-4**:确保导入功能能够正确处理不同版本的备份文件格式

## 非功能需求
- **NFR-1**:导入功能的性能不应受到影响
- **NFR-2**:修改后的导入功能应保持向后兼容性
- **NFR-3**:导入过程中的错误处理应更加健壮

## 约束
- **技术**:基于现有的TypeScript代码结构,不引入新的依赖
- **业务**:保持导入功能的核心逻辑不变,只修改检测和验证部分
- **依赖**:依赖现有的数据库操作和事务处理机制

## 假设
- 备份文件的基本结构保持不变
- 用户期望导入功能能够处理各种格式的备份文件
- 导入功能的性能要求保持不变

## 验收标准

### AC-1:账号数据检测修复
- **给定**:有效的账号数据备份文件
- **当**:用户尝试导入该备份文件
- **则**:导入功能应成功检测并导入账号数据
- **验证**:`programmatic`

### AC-2:设置数据检测修复
- **给定**:有效的设置数据备份文件
- **当**:用户尝试导入该备份文件
- **则**:导入功能应成功检测并导入设置数据
- **验证**:`programmatic`

### AC-3:错误信息改进
- **给定**:无效的备份文件
- **当**:用户尝试导入该备份文件
- **则**:用户应收到清晰、具体的错误信息,说明导入失败的具体原因
- **验证**:`human-judgment`

### AC-4:向后兼容性
- **给定**:使用旧版本备份文件
- **当**:用户尝试导入该备份文件
- **则**:导入功能应成功处理该文件,保持与旧版本的兼容性
- **验证**:`programmatic`

## 未解决问题
- [ ] 是否需要添加导入数据预览功能,让用户在导入前了解数据结构
- [ ] 是否需要添加导入失败时的自动修复机制
Loading