potpie-ai/potpie

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

オープン

#639 opened on 2026/02/24

 (2 件のコメント) (0 件のリアクション) (0 人の担当者)Python (642 件のフォーク)auto 404
good first issue

Repository metrics

Stars
 (5,521 個のスター)
PR merge metrics
 (平均マージ 5d 8h) (30d で 25 merged PRs)

説明

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!

コントリビューターガイド