From aac419fa2e0412f69bdf06747b56a7706e2d4aaf Mon Sep 17 00:00:00 2001 From: Egbert Bouman Date: Sun, 20 Oct 2024 17:19:33 +0200 Subject: [PATCH 1/2] Fix empty download list when ratio is infinity --- .../core/libtorrent/download_manager/download_state.py | 4 ++-- .../libtorrent/download_manager/test_download_state.py | 3 +-- src/tribler/ui/src/pages/Downloads/Details.tsx | 7 ++++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/tribler/core/libtorrent/download_manager/download_state.py b/src/tribler/core/libtorrent/download_manager/download_state.py index 655a1d977e..e618521a43 100644 --- a/src/tribler/core/libtorrent/download_manager/download_state.py +++ b/src/tribler/core/libtorrent/download_manager/download_state.py @@ -6,7 +6,6 @@ from __future__ import annotations import logging -import math from enum import Enum from typing import TYPE_CHECKING @@ -214,7 +213,8 @@ def get_all_time_ratio(self) -> float: return 0 if not self.all_time_download: - return 0 if not self.all_time_upload else math.inf + # We're returning -1 instead of infinity, as it avoids issues when JSON encoding. + return 0 if not self.all_time_upload else -1 return self.all_time_upload / self.all_time_download diff --git a/src/tribler/test_unit/core/libtorrent/download_manager/test_download_state.py b/src/tribler/test_unit/core/libtorrent/download_manager/test_download_state.py index 9096a177c2..d706304edf 100644 --- a/src/tribler/test_unit/core/libtorrent/download_manager/test_download_state.py +++ b/src/tribler/test_unit/core/libtorrent/download_manager/test_download_state.py @@ -1,4 +1,3 @@ -import math from io import StringIO from pathlib import Path from unittest.mock import Mock @@ -116,7 +115,7 @@ def test_all_time_ratio_no_all_time_download_inf(self) -> None: """ state = DownloadState(Mock(), Mock(all_time_upload=200, all_time_download=0), None) - self.assertEqual(math.inf, state.get_all_time_ratio()) + self.assertEqual(-1, state.get_all_time_ratio()) def test_get_files_completion(self) -> None: """ diff --git a/src/tribler/ui/src/pages/Downloads/Details.tsx b/src/tribler/ui/src/pages/Downloads/Details.tsx index ca5b6649ab..7f4c156262 100644 --- a/src/tribler/ui/src/pages/Downloads/Details.tsx +++ b/src/tribler/ui/src/pages/Downloads/Details.tsx @@ -68,7 +68,12 @@ export default function DownloadDetails({ selectedDownloads }: { selectedDownloa
{t('Ratio')}
-
{download?.all_time_ratio.toFixed(2)} ({formatBytes(download?.all_time_upload)} upload; {formatBytes(download?.all_time_download)} dowload)
+
{ + download.all_time_ratio < 0 ? + String(`∞`) : + download?.all_time_ratio.toFixed(2)} +  ({formatBytes(download?.all_time_upload)} upload; {formatBytes(download?.all_time_download)} dowload) +
{t('Availability')}
From 0853b6d2e8cd81ca83dd8244645ce853a150883e Mon Sep 17 00:00:00 2001 From: Egbert Bouman Date: Mon, 21 Oct 2024 09:50:17 +0200 Subject: [PATCH 2/2] Fix seeding settings --- src/tribler/ui/src/pages/Settings/Seeding.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tribler/ui/src/pages/Settings/Seeding.tsx b/src/tribler/ui/src/pages/Settings/Seeding.tsx index 0cf89fbf27..189f58f804 100644 --- a/src/tribler/ui/src/pages/Settings/Seeding.tsx +++ b/src/tribler/ui/src/pages/Settings/Seeding.tsx @@ -31,7 +31,7 @@ export default function Seeding() { return (
{ if (settings) { setSettings({