Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query peers for popular torrents #8153

Merged
merged 1 commit into from
Sep 16, 2024
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
2 changes: 2 additions & 0 deletions src/tribler/core/database/restapi/database_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def sanitize_parameters(cls: type[Self],
sanitized["channel_pk"] = unhexlify(parameters["channel_pk"])
if "origin_id" in parameters:
sanitized["origin_id"] = int(parameters["origin_id"])
if "popular" in parameters and parse_bool(parameters.get("popular", "false")):
sanitized["sort_by"] = "HEALTH"
return sanitized

@db_session
Expand Down
22 changes: 21 additions & 1 deletion src/tribler/ui/src/pages/Popular/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SimpleTable from "@/components/ui/simple-table";
import SaveAs from "@/dialogs/SaveAs";
import { useCallback, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { triblerService } from "@/services/tribler.service";
import { Torrent } from "@/models/torrent.model";
import { ColumnDef } from "@tanstack/react-table";
Expand Down Expand Up @@ -57,12 +57,32 @@ export default function Popular() {
const [open, setOpen] = useState<boolean>(false)
const [torrents, setTorrents] = useState<Torrent[]>([])
const [torrentDoubleClicked, setTorrentDoubleClicked] = useState<Torrent | undefined>();
const [request, setRequest] = useState<string>("");

useInterval(async () => {
const popular = await triblerService.getPopularTorrents(true);
setTorrents(filterDuplicates(popular, 'infohash'));
const remoteQuery = await triblerService.searchTorrentsRemote('', true);
setRequest(remoteQuery.request_uuid);
}, 5000, true);

useEffect(() => {
egbertbouman marked this conversation as resolved.
Show resolved Hide resolved
(async () => { triblerService.addEventListener("remote_query_results", OnSearchEvent) })();
return () => {
(async () => { triblerService.removeEventListener("remote_query_results", OnSearchEvent) })();
}
}, [request]);

const OnSearchEvent = (event: MessageEvent) => {
const data = JSON.parse(event.data);
if (data.uuid !== request)
return;

for (const result of data.results) {
setTorrents((prevTorrents) => [...prevTorrents, result]);
}
}

const handleDownload = useCallback((torrent: Torrent) => {
setTorrentDoubleClicked(torrent);
setOpen(true);
Expand Down
4 changes: 2 additions & 2 deletions src/tribler/ui/src/pages/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export default function Search() {
useEffect(() => {
const searchTorrents = async () => {
if (!query) return;
const localResults = await triblerService.searchTorrentsLocal(query, true);
const localResults = await triblerService.searchTorrentsLocal(query);
setTorrents(filterDuplicates(localResults, 'infohash'));
const remoteQuery = await triblerService.searchTorrentsRemote(query, true);
const remoteQuery = await triblerService.searchTorrentsRemote(query, false);
setRequest(remoteQuery.request_uuid);
}
searchTorrents();
Expand Down
8 changes: 4 additions & 4 deletions src/tribler/ui/src/services/tribler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ export class TriblerService {
return (await this.http.get(`/metadata/search/completions?q=${txt_filter}`)).data.completions;
}

async searchTorrentsLocal(txt_filter: string, hide_xxx: boolean): Promise<Torrent[]> {
return (await this.http.get(`/metadata/search/local?first=1&last=200&metadata_type=300&exclude_deleted=1&fts_text=${txt_filter}&hide_xxx=${+hide_xxx}`)).data.results;
async searchTorrentsLocal(txt_filter: string): Promise<Torrent[]> {
return (await this.http.get(`/metadata/search/local?first=1&last=200&metadata_type=300&exclude_deleted=1&fts_text=${txt_filter}`)).data.results;
}

async searchTorrentsRemote(txt_filter: string, hide_xxx: boolean): Promise<{ request_uuid: string, peers: string[] }> {
return (await this.http.put(`/search/remote?fts_text=${txt_filter}&hide_xxx=${+hide_xxx}&metadata_type=300&exclude_deleted=1`)).data;
async searchTorrentsRemote(txt_filter: string, popular: boolean): Promise<{ request_uuid: string, peers: string[] }> {
return (await this.http.put(`/search/remote?fts_text=${txt_filter}&popular=${+popular}&metadata_type=300&exclude_deleted=1`)).data;
egbertbouman marked this conversation as resolved.
Show resolved Hide resolved
}

// Settings
Expand Down