1. PostgREST 使用情况分析文档 - PostgREST使用情况-后端API替代建议.md: 完整的迁移建议和优先级分析 - PostgREST实际使用清单.md: 当前使用的 PostgREST 接口清单 - PostgREST未使用函数清单.md: 已封装但未使用的函数列表 - PostgREST请求模块清单.md: 所有请求模块的使用情况 2. 删除操作延迟确认功能实施文档 - 功能设计和实现细节 - 使用示例和最佳实践 - 技术实现说明 这些文档用于: - 追踪 PostgREST 到 FastAPI 的迁移进度 - 指导后续的接口迁移工作 - 记录 UI 改进的实施细节 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
8.7 KiB
PostgREST 未使用函数清单
本文档记录所有定义了但未被实际引用的 PostgREST 相关函数 更新时间: 2025-11-25
📋 目录
完全未使用的函数
这些函数被导出但在整个项目中没有任何地方调用。
1. ❌ getUserBySub()
文件: app/api/login/auth.server.ts
行号: 746
PostgREST 操作: postgrestGet
表名: sso_users
export async function getUserBySub(sub: string) {
const userResult = await postgrestGet<SsoUser[]>("sso_users", {
filter: { sub: `eq.${sub}` }
});
// ...
}
搜索结果: 只在定义文件中出现 1 次 建议: 🗑️ 可以删除
2. ❌ getDocumentHistory()
文件: app/api/files/documents.ts
行号: 665
PostgREST 操作: postgrestPost (RPC)
RPC 函数: rpc/documents_get_document_history
export async function getDocumentHistory(
documentName: string,
userId: string,
excludeId: number,
token?: string
): Promise<{data?: DocumentVersionUI[]; error?: string; status?: number}> {
const response = await postgrestPost<any[], unknown>(
'rpc/documents_get_document_history',
{ p_document_name, p_user_id, p_exclude_id },
token
);
// ...
}
搜索结果: routes 和 components 中 0 次引用
建议: 🗑️ 可以删除 (新API已改用 /admin/versions/documents-list)
3. ❌ duplicateRule()
文件: app/api/evaluation_points/rules.ts
行号: 740
PostgREST 操作: postgrestGet + postgrestPost
表名: evaluation_points
export async function duplicateRule(id: string, token?: string): Promise<{
data: Rule;
error?: never
} | {
data?: never;
error: string;
status?: number
}> {
// 1. 获取原规则
const originalRule = await postgrestGet(...);
// 2. 创建副本
const result = await postgrestPost(...);
// ...
}
搜索结果: 只在定义文件中出现 1 次 建议: 🔄 保留但标记为未来功能 (复制功能可能有计划)
4. ❌ getEvaluationPointGroupsByIds()
文件: app/api/document-types/document-types.ts
行号: 245
PostgREST 操作: postgrestGet
表名: evaluation_point_groups
export async function getEvaluationPointGroupsByIds(
ids: number[] | number,
token?: string
): Promise<{
data: EvaluationPointGroup[];
error?: never
} | {
data?: never;
error: string;
status?: number
}> {
const response = await postgrestGet<EvaluationPointGroup[]>(
"evaluation_point_groups",
{
filter: { id: `in.(${idsArray.join(',')})` },
token
}
);
// ...
}
搜索结果: 只在定义文件中出现 5 次(都是定义和类型导出) 建议: 🗑️ 可以删除
5. ❌ createSimpleUserSession()
文件: app/api/login/auth.server.ts
行号: 412
PostgREST 操作: 无(仅 session 管理)
export async function createSimpleUserSession(
isAuthenticated: boolean,
userRole: UserRole,
redirectTo: string
) {
const session = await sessionStorage.getSession();
session.set("isAuthenticated", isAuthenticated);
session.set("userRole", userRole);
// ...
}
搜索结果: 只在定义文件中出现 1 次
建议: 🗑️ 可以删除 (已统一使用 createUserSession)
6. ❌ getFeaturedTemplates()
文件: app/api/contract-template/templates.ts
行号: 347
PostgREST 操作: postgrestGet
表名: contract_templates
export async function getFeaturedTemplates(
limit: number = 6,
jwt?: string
) {
const response = await postgrestGet<ContractTemplate[]>(
'contract_templates',
{
filter: { is_featured: 'eq.true' },
order: 'created_at.desc',
limit: limit,
token: jwt
}
);
// ...
}
搜索结果: 只在定义文件中出现 1 次 建议: 🔄 保留但标记为未来功能 (推荐模板功能可能有计划)
仅内部使用的函数
这些函数虽然被导出,但只在同一个文件内部被调用,不被其他文件引用。
7. ⚠️ getEvaluationResults()
文件: app/api/files/documents.ts
行号: 147-159
PostgREST 操作: postgrestGet
表名: evaluation_results
async function getEvaluationResults(id: number, frontendJWT?: string) {
const response = await postgrestGet<[]>('evaluation_results', {
filter: { 'document_id': `eq.${id}` },
token: frontendJWT
});
// ...
}
搜索结果: 只在 documents.ts 内部被 convertToUIDocument() 调用
建议: ✅ 改为内部函数(去掉 export)
8. ⚠️ convertToUIDocument()
文件: app/api/files/documents.ts
行号: 165
PostgREST 操作: 调用 getEvaluationResults()
表名: 间接查询 evaluation_results
async function convertToUIDocument(
doc: Document,
frontendJWT?: string
): Promise<DocumentUI> {
const evaluationResult = await getEvaluationResults(doc.id, frontendJWT);
// ...
}
搜索结果: 只在 documents.ts 内部被其他函数调用
建议: ✅ 改为内部函数(去掉 export)
9. ⚠️ convertApiRuleToFormData()
文件: app/api/evaluation_points/rules.ts
行号: 1079
PostgREST 操作: 无(数据转换函数)
export function convertApiRuleToFormData(
apiRule: ApiRule
): FormattedEvaluationPoint {
// 数据格式转换
}
搜索结果: 只在定义文件中出现 4 次(内部调用) 建议: ✅ 改为内部函数(去掉 export)
10. ⚠️ convertToUITemplate()
文件: app/api/prompts/prompts.ts
行号: 102
PostgREST 操作: 无(数据转换函数)
export function convertToUITemplate(
template: PromptTemplate & { sso_users?: { username: string } }
): PromptTemplateUI {
// 数据格式转换
}
搜索结果: 只在定义文件中出现 5 次(内部调用) 建议: ✅ 改为内部函数(去掉 export)
建议的清理操作
🗑️ 立即删除(6 个函数)
| 序号 | 函数名 | 文件 | 原因 |
|---|---|---|---|
| 1 | getUserBySub() |
auth.server.ts |
完全未使用 |
| 2 | getDocumentHistory() |
documents.ts |
已被新 API 替代 |
| 3 | getEvaluationPointGroupsByIds() |
document-types.ts |
完全未使用 |
| 4 | createSimpleUserSession() |
auth.server.ts |
已统一使用 createUserSession |
| 5 | duplicateRule() |
rules.ts |
保留(可能是未来功能) |
| 6 | getFeaturedTemplates() |
templates.ts |
保留(可能是未来功能) |
实际建议删除: 4 个函数
✅ 改为私有函数(4 个函数)
将这些仅内部使用的函数改为非导出(去掉 export 关键字):
| 序号 | 函数名 | 文件 | 操作 |
|---|---|---|---|
| 1 | getEvaluationResults() |
documents.ts |
去掉 export |
| 2 | convertToUIDocument() |
documents.ts |
去掉 export |
| 3 | convertApiRuleToFormData() |
rules.ts |
去掉 export |
| 4 | convertToUITemplate() |
prompts.ts |
去掉 export |
🔄 保留但标记的函数(2 个)
这些函数虽然当前未使用,但可能是计划中的功能:
| 序号 | 函数名 | 文件 | 建议 |
|---|---|---|---|
| 1 | duplicateRule() |
rules.ts |
添加 @deprecated 或 @future 注释 |
| 2 | getFeaturedTemplates() |
templates.ts |
添加 @deprecated 或 @future 注释 |
📊 统计总结
| 类别 | 数量 |
|---|---|
| ❌ 完全未使用(建议删除) | 4 |
| ⚠️ 仅内部使用(改为私有) | 4 |
| 🔄 保留但标记 | 2 |
| 总计 | 10 |
🔍 检查方法
使用以下命令检查函数引用:
# 检查函数是否被引用(在 routes 和 components 中)
grep -r "函数名" app/routes app/components --include="*.ts" --include="*.tsx"
# 或使用 Grep 工具
Grep: pattern="函数名", glob="app/**/*.{ts,tsx}", output_mode="count"
⚠️ 注意事项
- 删除前再次确认: 虽然这些函数当前未被引用,但可能在其他分支或未来功能中需要
- Git 历史: 删除前检查 Git 历史,看是否之前被使用过
- API 兼容性: 如果这些函数是 API 的一部分,删除可能影响其他项目
- 测试代码: 检查测试文件中是否有引用(本次未扫描测试文件)
维护建议: 定期运行此检查,避免积累过多死代码。