Skip to content

Commit f8de087

Browse files
authored
Various fixes (#8315)
2 parents 7edcb76 + c22322e commit f8de087

File tree

5 files changed

+53
-46
lines changed

5 files changed

+53
-46
lines changed

Diff for: src/tribler/core/libtorrent/download_manager/download_state.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,12 @@ def get_all_time_ratio(self) -> float:
212212
if not self.lt_status:
213213
return 0
214214

215-
if not self.all_time_download:
215+
bytes_completed = self.get_progress() * self.download.tdef.get_length()
216+
if not bytes_completed:
216217
# We're returning -1 instead of infinity, as it avoids issues when JSON encoding.
217218
return 0 if not self.all_time_upload else -1
218219

219-
return self.all_time_upload / self.all_time_download
220+
return self.all_time_upload / bytes_completed
220221

221222
def get_seeding_time(self) -> int:
222223
"""
@@ -316,7 +317,7 @@ def get_availability(self) -> float:
316317
completed = peer.get('completed', 0)
317318
have = peer.get('have', [])
318319

319-
if completed == 1 or have and all(have):
320+
if completed == 1 or (have and all(have)):
320321
nr_seeders_complete += 1
321322
elif have and len(have) == len(merged_bitfields):
322323
for i in range(len(have)):

Diff for: src/tribler/test_unit/core/libtorrent/download_manager/test_download_state.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,26 @@ def test_all_time_ratio(self) -> None:
9797
"""
9898
Test if the all-time ratio is the fraction of the all-time up and down.
9999
"""
100-
state = DownloadState(Mock(), Mock(all_time_upload=200, all_time_download=1000), None)
100+
tdef = Mock(get_length=Mock(return_value=1000))
101+
state = DownloadState(Mock(tdef=tdef), Mock(progress=1, all_time_upload=200), None)
101102

102103
self.assertEqual(0.2, state.get_all_time_ratio())
103104

104105
def test_all_time_ratio_no_all_time_download(self) -> None:
105106
"""
106107
Test if the all-time ratio is 0 when the all-time up and down are both 0.
107108
"""
108-
state = DownloadState(Mock(), Mock(all_time_upload=0, all_time_download=0), None)
109+
tdef = Mock(get_length=Mock(return_value=1000))
110+
state = DownloadState(Mock(tdef=tdef), Mock(progress=0, all_time_upload=0), None)
109111

110112
self.assertEqual(0, state.get_all_time_ratio())
111113

112114
def test_all_time_ratio_no_all_time_download_inf(self) -> None:
113115
"""
114116
Test if the all-time ratio is 0 when the all-time download is 0.
115117
"""
116-
state = DownloadState(Mock(), Mock(all_time_upload=200, all_time_download=0), None)
118+
tdef = Mock(get_length=Mock(return_value=1000))
119+
state = DownloadState(Mock(tdef=tdef), Mock(progress=0, all_time_upload=1000), None)
117120

118121
self.assertEqual(-1, state.get_all_time_ratio())
119122

Diff for: src/tribler/ui/src/pages/Downloads/Details.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -57,40 +57,40 @@ export default function DownloadDetails({ selectedDownloads }: { selectedDownloa
5757
</div>
5858
<div className="flex flex-row">
5959
<div className="basis-1/4">{t('Name')}</div>
60-
<div className="basis-3/4 break-all line-clamp-1">{download?.name}</div>
60+
<div className="basis-3/4 break-all line-clamp-1">{download.name}</div>
6161
</div>
6262
<div className="flex flex-row">
6363
<div className="basis-1/4">{t('Status')}</div>
64-
<div className="basis-3/4">{capitalize(download?.status)}</div>
64+
<div className="basis-3/4">{capitalize(download.status)}</div>
6565
</div>
6666
<div className="flex flex-row">
6767
<div className="basis-1/4">{t('Filesize')}</div>
68-
<div className="basis-3/4">{formatBytes(download?.size)}</div>
68+
<div className="basis-3/4">{formatBytes(download.size)}</div>
6969
</div>
7070
<div className="flex flex-row">
7171
<div className="basis-1/4">{t('Health')}</div>
72-
<div className="basis-3/4">{t('SeedersLeechers', { seeders: download?.num_seeds, leechers: download?.num_peers })}</div>
72+
<div className="basis-3/4">{t('SeedersLeechers', { seeders: download.num_seeds, leechers: download.num_peers })}</div>
7373
</div>
7474
<div className="flex flex-row">
7575
<div className="basis-1/4">{t('Infohash')}</div>
76-
<div className="basis-3/4">{download?.infohash}</div>
76+
<div className="basis-3/4">{download.infohash}</div>
7777
</div>
7878
<div className="flex flex-row">
7979
<div className="basis-1/4">{t('Destination')}</div>
80-
<div className="basis-3/4 break-all line-clamp-1">{download?.destination}</div>
80+
<div className="basis-3/4 break-all line-clamp-1">{download.destination}</div>
8181
</div>
8282
<div className="flex flex-row">
8383
<div className="basis-1/4">{t('Ratio')}</div>
8484
<div className="basis-3/4">{
8585
download.all_time_ratio < 0 ?
8686
String(`∞`) :
87-
download?.all_time_ratio.toFixed(2)}
88-
&nbsp;({formatBytes(download?.all_time_upload)} upload; {formatBytes(download?.all_time_download)} dowload)
87+
download.all_time_ratio.toFixed(2)}
88+
&nbsp;({formatBytes(download.all_time_upload)} / {formatBytes(download.size * download.progress)})
8989
</div>
9090
</div>
9191
<div className="flex flex-row">
9292
<div className="basis-1/4">{t('Availability')}</div>
93-
<div className="basis-3/4">{download?.availability}</div>
93+
<div className="basis-3/4">{download.availability}</div>
9494
</div>
9595
</div>
9696
</ScrollArea>
@@ -107,7 +107,7 @@ export default function DownloadDetails({ selectedDownloads }: { selectedDownloa
107107
</TabsContent>
108108
<TabsContent value="peers" style={contentStyle}>
109109
<ScrollArea className="h-full">
110-
<Peers download={download} height={contentStyle.height}/>
110+
<Peers download={download} height={contentStyle.height} />
111111
</ScrollArea>
112112
</TabsContent>
113113
</Tabs>

Diff for: src/tribler/ui/src/pages/Popular/index.tsx

+21-24
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import SimpleTable, { getHeader } from "@/components/ui/simple-table";
22
import SaveAs from "@/dialogs/SaveAs";
3-
import { useCallback, useEffect, useMemo, useState } from "react";
3+
import { useCallback, useMemo, useState } from "react";
44
import { triblerService } from "@/services/tribler.service";
55
import { isErrorDict } from "@/services/reporting";
66
import { Torrent } from "@/models/torrent.model";
77
import { ColumnDef } from "@tanstack/react-table";
88
import { categoryIcon, filterDuplicates, formatBytes, formatTimeAgo, getMagnetLink } from "@/lib/utils";
99
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
1010
import { useInterval } from '@/hooks/useInterval';
11+
import { SwarmHealth } from "@/components/swarm-health";
1112

1213

1314
const getColumns = ({ onDownload }: { onDownload: (torrent: Torrent) => void }): ColumnDef<Torrent>[] => [
@@ -49,7 +50,20 @@ const getColumns = ({ onDownload }: { onDownload: (torrent: Torrent) => void }):
4950
accessorKey: "created",
5051
header: getHeader('Created'),
5152
cell: ({ row }) => {
52-
return <span className="whitespace-nowrap">{formatTimeAgo(row.original.created)}</span>
53+
return (
54+
<span className="whitespace-nowrap">
55+
{row.original.created > 24 * 3600 ?
56+
formatTimeAgo(row.original.created) :
57+
"unknown"}
58+
</span>
59+
)
60+
},
61+
},
62+
{
63+
accessorKey: "num_seeders",
64+
header: getHeader("Health"),
65+
cell: ({ row }) => {
66+
return <SwarmHealth torrent={row.original} />
5367
},
5468
},
5569
]
@@ -58,36 +72,19 @@ export default function Popular() {
5872
const [open, setOpen] = useState<boolean>(false)
5973
const [torrents, setTorrents] = useState<Torrent[]>([])
6074
const [torrentDoubleClicked, setTorrentDoubleClicked] = useState<Torrent | undefined>();
61-
const [request, setRequest] = useState<string>("");
6275

6376
useInterval(async () => {
6477
const popular = await triblerService.getPopularTorrents();
6578
if (!(popular === undefined) && !isErrorDict(popular)) {
6679
// Don't bother the user on error, just try again later.
6780
setTorrents(filterDuplicates(popular, 'infohash'));
6881
}
69-
const remoteQuery = await triblerService.searchTorrentsRemote('', true);
70-
if (!(remoteQuery === undefined) && !isErrorDict(remoteQuery)) {
71-
setRequest(remoteQuery.request_uuid);
72-
}
73-
}, 5000, true);
74-
75-
useEffect(() => {
76-
(async () => { triblerService.addEventListener("remote_query_results", OnSearchEvent) })();
77-
return () => {
78-
(async () => { triblerService.removeEventListener("remote_query_results", OnSearchEvent) })();
79-
}
80-
}, [request]);
8182

82-
const OnSearchEvent = (event: MessageEvent) => {
83-
const data = JSON.parse(event.data);
84-
if (data.uuid !== request)
85-
return;
86-
87-
for (const result of data.results) {
88-
setTorrents((prevTorrents) => [...prevTorrents, result]);
89-
}
90-
}
83+
await triblerService.searchTorrentsRemote('', true);
84+
// We're not processing incoming results from remote search, instead additional
85+
// results will appear during the next run. This prevents issues with torrents
86+
// quickly being added and removed.
87+
}, 5000, true);
9188

9289
const handleDownload = useCallback((torrent: Torrent) => {
9390
setTorrentDoubleClicked(torrent);

Diff for: src/tribler/ui/src/pages/Search/index.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,23 @@ const getColumns = ({ onDownload }: { onDownload: (torrent: Torrent) => void }):
4747
},
4848
},
4949
{
50-
accessorKey: "num_seeders",
51-
header: getHeader("Health"),
50+
accessorKey: "created",
51+
header: getHeader("Created"),
5252
cell: ({ row }) => {
53-
return <SwarmHealth torrent={row.original} />
53+
return (
54+
<span className="whitespace-nowrap">
55+
{row.original.created > 24 * 3600 ?
56+
formatTimeAgo(row.original.created) :
57+
"unknown"}
58+
</span>
59+
)
5460
},
5561
},
5662
{
57-
accessorKey: "created",
58-
header: getHeader("Created"),
63+
accessorKey: "num_seeders",
64+
header: getHeader("Health"),
5965
cell: ({ row }) => {
60-
return <span className="whitespace-nowrap">{formatTimeAgo(row.original.created)}</span>
66+
return <SwarmHealth torrent={row.original} />
6167
},
6268
},
6369
]

0 commit comments

Comments
 (0)