Skip to content

Commit

Permalink
Fix empty download list when ratio is infinity (#8228)
Browse files Browse the repository at this point in the history
  • Loading branch information
egbertbouman authored Oct 21, 2024
2 parents faef65d + 0853b6d commit 71d4d97
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from __future__ import annotations

import logging
import math
from enum import Enum
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import math
from io import StringIO
from pathlib import Path
from unittest.mock import Mock
Expand Down Expand Up @@ -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:
"""
Expand Down
7 changes: 6 additions & 1 deletion src/tribler/ui/src/pages/Downloads/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ export default function DownloadDetails({ selectedDownloads }: { selectedDownloa
</div>
<div className="flex flex-row">
<div className="basis-1/4">{t('Ratio')}</div>
<div className="basis-3/4">{download?.all_time_ratio.toFixed(2)} ({formatBytes(download?.all_time_upload)} upload; {formatBytes(download?.all_time_download)} dowload)</div>
<div className="basis-3/4">{
download.all_time_ratio < 0 ?
String(`∞`) :
download?.all_time_ratio.toFixed(2)}
&nbsp;({formatBytes(download?.all_time_upload)} upload; {formatBytes(download?.all_time_download)} dowload)
</div>
</div>
<div className="flex flex-row">
<div className="basis-1/4">{t('Availability')}</div>
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/ui/src/pages/Settings/Seeding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function Seeding() {
return (
<div className="p-6 w-full">
<RadioGroup
defaultValue="forever"
defaultValue={settings?.libtorrent?.download_defaults?.seeding_mode || "forever"}
onValueChange={(value) => {
if (settings) {
setSettings({
Expand Down

0 comments on commit 71d4d97

Please sign in to comment.