Skip to content
Merged
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
20 changes: 19 additions & 1 deletion src/codegraphcontext/tools/indexing/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@
)


DEFAULT_PARALLEL_WORKERS = 10


def get_parallel_workers() -> int:
"""Resolve the indexing concurrency limit from the PARALLEL_WORKERS config.

Falls back to DEFAULT_PARALLEL_WORKERS when the value is unset or not a
usable positive integer, so a bad config never breaks indexing.
"""
from ...cli.config_manager import get_config_value

try:
workers = int(get_config_value("PARALLEL_WORKERS") or "")
except (TypeError, ValueError):
return DEFAULT_PARALLEL_WORKERS
return workers if workers > 0 else DEFAULT_PARALLEL_WORKERS


def build_index_summary(
files: List[Path],
parsers: Dict[str, str],
Expand Down Expand Up @@ -108,7 +126,7 @@ async def run_tree_sitter_index_async(
resolved_repo_path_str = path.resolve().as_posix() if path.is_dir() else path.parent.resolve().as_posix()

processed_count = 0
concurrency_limit = 10
concurrency_limit = get_parallel_workers()
semaphore = asyncio.Semaphore(concurrency_limit)

async def process_file(file: Path) -> Optional[Dict[str, Any]]:
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/tools/test_pipeline_parallel_workers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Tests that the PARALLEL_WORKERS config drives indexing concurrency (#1340)."""
from unittest import mock

import pytest

from codegraphcontext.tools.indexing import pipeline


@pytest.mark.parametrize(
"config_value,expected",
[
("32", 32),
("1", 1),
("4", 4),
(None, pipeline.DEFAULT_PARALLEL_WORKERS),
("", pipeline.DEFAULT_PARALLEL_WORKERS),
("not-a-number", pipeline.DEFAULT_PARALLEL_WORKERS),
("0", pipeline.DEFAULT_PARALLEL_WORKERS),
("-5", pipeline.DEFAULT_PARALLEL_WORKERS),
],
)
def test_get_parallel_workers(config_value, expected):
with mock.patch(
"codegraphcontext.cli.config_manager.get_config_value",
return_value=config_value,
):
assert pipeline.get_parallel_workers() == expected
Loading