potpie-ai/potpie

[Bug/Performance]: Inconsistent async DB usage in fetch_parsing_status causes blocking calls

开放

#639 创建于 2026年2月24日

 (2 条评论) (0 个反应) (0 位负责人)Python (642 个派生)auto 404
good first issue

仓库指标

星标
 (5,521 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

Component/Module

Parsing (Graph Construction)

Feature Type

Bug Fix / Performance Enhancement

Problem Statement

The ParsingController.fetch_parsing_status method in app/modules/parsing/graph_construction/parsing_controller.py is declared as async but uses a synchronous SQLAlchemy Session and calls db.execute(...) directly.

This mixes blocking database I/O inside an asynchronous FastAPI handler. Doing this can block the event loop and significantly reduce throughput and performance under load. It is also inconsistent with the fetch_parsing_status_by_repo method in the same file, which correctly uses AsyncSession and await for its database access.

Proposed Solution

The async controller method should be completely non-blocking. To achieve this:

  1. Change the fetch_parsing_status method signature to accept db: AsyncSession instead of a synchronous Session.
  2. Update the router/dependencies that call this method to provide an AsyncSession.
  3. Replace the synchronous result = db.execute(project_query) execution with the asynchronous pattern: result = await db.execute(project_query).
  4. Note: If ParseHelper inside this method requires a synchronous Session, you must either adapt it to use async DB accesses, or delegate its blocking parts to a separate thread via asyncio.to_thread (or a dedicated synchronous service layer).

Current Implementation:

  • fetch_parsing_status accepts db: Session.
  • It calls db.execute(project_query) synchronously inside an async def.

After this change:

  • The method accepts an AsyncSession and awaits DB queries.
  • Operations match the correct async patterns already established by fetch_parsing_status_by_repo.

Use Case

FastAPI relies on the asyncio event loop. By removing blocking I/O calls from async handlers, we ensure that the API can handle more concurrent requests without introducing performance bottlenecks during parsing status checks.

Additional Context

Where to look:

  • app/modules/parsing/graph_construction/parsing_controller.py - Look at fetch_parsing_status and compare it to fetch_parsing_status_by_repo.

Skill level needed: Intermediate Python. Familiarity with FastAPI, SQLAlchemy, and Python's asyncio is required.

Feel free to comment if you have any questions before you start!

贡献者指南