Skip to content

Conversation

@brucegorman
Copy link

This PR adds a new WebAPI endpoint:

GET /api/v2/torrents/stats

Purpose

For users with a large number of torrents, /sync/maindata can be expensive because it always returns full torrent metadata.
This endpoint provides a lightweight alternative by returning only the counts of torrents per underlying TorrentState, as requested in issue #23449.

What it returns

A JSON object mapping each TorrentState to its torrent count.
Keys follow the existing WebAPI naming convention (snake_case), e.g.:

{
"downloading": 12,
"uploading": 4,
"queued_downloading": 5,
"stalled_downloading": 3,
"error": 2
// not putting all states here though
}

Implementation details

  • Counts are computed directly from the session’s torrent list.
  • A fixed-length array indexed by normalized enum values (raw - minState) ensures O(n) performance with minimal overhead.
  • JSON keys are defined as constants for consistency with other WebAPI endpoints.
  • Fully backward-compatible, no changes to Sync API behavior.

Fixes

Fixes #23449

@thalieht thalieht added the WebAPI WebAPI-related issues/changes label Nov 25, 2025
@glassez glassez changed the title Add /api/v2/torrents/stats endpoint to return per-state torrent counts WebAPI: Add "torrents/stats" endpoint to return per-state torrent counts Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WebAPI WebAPI-related issues/changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API Endpoint to return Counts only

2 participants