Skip to content

[Low] 代码质量 - 优化插件 URL 查重性能 #15

Description

@Qixuan112

问题描述

插件提交时的 URL 查重使用全表扫描,性能较差。

当前实现

for p in db.session.query(Plugin).filter(Plugin.repo_url.isnot(None)).all():
    if _normalize_repo_url(p.repo_url) == normalized:
        existing = p
        break

风险

  • O(n) 复杂度,数据量大时性能差
  • 全表扫描

修复建议

方案 1:添加规范化 URL 字段

# 在 Plugin 模型添加字段
normalized_repo_url: Mapped[str] = mapped_column(String(500), unique=True, index=True)

# 查重时直接查询
existing = db.session.query(Plugin).filter(
    Plugin.normalized_repo_url == normalized
).first()

方案 2:使用数据库函数

在 SQLite/MySQL 中使用 LOWER() 函数进行大小写不敏感查询。

相关文件

  • backend/app/services/developer_service.py:200-206

优先级

Low - 性能优化,非紧急

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions