diff --git a/src/tribler/core/content_discovery/payload.py b/src/tribler/core/content_discovery/payload.py index 9bed398515..42b02644a8 100644 --- a/src/tribler/core/content_discovery/payload.py +++ b/src/tribler/core/content_discovery/payload.py @@ -17,7 +17,7 @@ class TorrentInfoFormat(VariablePayload): """ format_list = ["20s", "I", "I", "Q"] - names = ["infohash", "seeders", "leechers", "timestamp"] + names = ["infohash", "seeders", " leechers", "timestamp"] length = 36 infohash: bytes diff --git a/src/tribler/core/recommender/community.py b/src/tribler/core/recommender/community.py index 2abc874cbb..7d21a1b126 100644 --- a/src/tribler/core/recommender/community.py +++ b/src/tribler/core/recommender/community.py @@ -68,7 +68,7 @@ def create_crawl_query_info(query_id: int) -> dict: } -def create_crawl_query_info_response(query_id: int, results: int, chosen_index: int, query: str) -> dict: +def create_crawl_query_info_response(query_id: int, timestamp: int, results: int, chosen_index: int, query: str) -> dict: """ A response with the number of available results for the query with the id ``query_id``. """ @@ -78,6 +78,7 @@ def create_crawl_query_info_response(query_id: int, results: int, chosen_index: "query_id": query_id, "results": results, "chosen_index": chosen_index, + "timestamp": timestamp, "query": query } @@ -176,7 +177,8 @@ def process_query_info(self, peer: Peer, request: dict) -> None: query_id=query.rowid, results=len(unpacked["results"]), chosen_index=unpacked["chosen_index"], - query=unpacked["query"] + timestamp=unpacked["timestamp"], + query=unpacked["query"], )), b"")) @lazy_wrapper(Crawl) @@ -220,6 +222,7 @@ def __init__(self, request_cache: RequestCache, peer: Peer, response: dict) -> N self.total_results = response["results"] self.results: list[ResultItem | None] = [None] * self.total_results self.chosen_index = response["chosen_index"] + self.timestamp = response["timestamp"] self.query = response["query"] def get_next_range(self) -> tuple[int, int] | None: @@ -300,7 +303,7 @@ def init_crawl_history(self) -> None: self.crawl_history[peer_mid] = (max_id, missing) def finalize_query(self, peer: Peer, query_id: int, query: str, chosen_index: int, - results: list[ResultItem]) -> None: + timestamp: int, results: list[ResultItem]) -> None: """ Update self.crawl_history and write the results to a file. """ @@ -308,6 +311,7 @@ def finalize_query(self, peer: Peer, query_id: int, query: str, chosen_index: in os.makedirs(query_dir, exist_ok=True) json_dict = { "query": query, + "timestamp": timestamp, "chosen_index": chosen_index, "results": results } @@ -356,7 +360,7 @@ def process_query_info_response(self, peer: Peer, response: dict) -> None: if next_range is None: self.logger.info("Query %d is empty for %s.", response["query_id"], str(peer)) - self.finalize_query(peer, cache.query_id, cache.query, cache.chosen_index, []) + self.finalize_query(peer, cache.query_id, cache.query, cache.chosen_index, cache.timestamp, []) else: self.request_cache.add(cache) self.ez_send(peer, Crawl(peer.mid, self.json_pack(create_crawl_fragment( @@ -375,7 +379,7 @@ def process_query_fragment_response(self, peer: Peer, response: dict) -> None: if next_range is None: self.logger.info("Query %d has completed for %s.", response["query_id"], str(peer)) - self.finalize_query(peer, cache.query_id, cache.query, cache.chosen_index, + self.finalize_query(peer, cache.query_id, cache.query, cache.chosen_index, cache.timestamp, cast(list[ResultItem] , cache.results)) else: self.request_cache.add(cache) # Reset the two-minute timer @@ -399,4 +403,4 @@ def on_crawl_response(self, peer: Peer, payload: CrawlResponse) -> None: elif request_type == "table_size": self.process_table_size_response(peer, response) else: - self.logger.warning("Crawlee sent unknown response type!") + self.logger.warning("Crawler sent unknown response type!") diff --git a/src/tribler/core/recommender/manager.py b/src/tribler/core/recommender/manager.py index 14b9d7f363..6d297e16f1 100644 --- a/src/tribler/core/recommender/manager.py +++ b/src/tribler/core/recommender/manager.py @@ -54,4 +54,4 @@ def add_query(self, json_data: str) -> None: Inject data into our database. """ with db_session: - self.Query(version=0, json=json_data) + self.Query(version=1, json=json_data) diff --git a/src/tribler/core/recommender/orm_query.py b/src/tribler/core/recommender/orm_query.py index 349c521b1b..811df9385b 100644 --- a/src/tribler/core/recommender/orm_query.py +++ b/src/tribler/core/recommender/orm_query.py @@ -29,6 +29,7 @@ class Query(Entity, metaclass=IterQuery): """ { chosen_index: int, + timestamp: int, query: str, results: [{infohash: str, seeders: int, leechers: int}] } diff --git a/src/tribler/core/recommender/restapi/endpoint.py b/src/tribler/core/recommender/restapi/endpoint.py index 60c9fc7390..76c3df8b9d 100644 --- a/src/tribler/core/recommender/restapi/endpoint.py +++ b/src/tribler/core/recommender/restapi/endpoint.py @@ -50,6 +50,7 @@ def __init__(self, middlewares: tuple = (), client_max_size: int = MAX_REQUEST_S @json_schema(schema(ClickedRequest={ "query": (String, "The query that led to the list of results"), "chosen_index": (String, "The winning result index in the results list"), + "timestamp": (Integer, "The timestamp of the query"), "results": (List(Nested(schema(ClickedResult={"infohash": (String, "A displayed infohash"), "seeders": (Integer, "Its displayed number of seeders"), "leechers": (Integer, "Its displayed number of seeders")}))), @@ -63,6 +64,7 @@ async def put_clicked(self, request: RequestType) -> RESTResponse: { query: str, chosen_index: int, + timestamp: int, results: list[{ infohash: str, seeders: int, diff --git a/src/tribler/ui/src/services/tribler.service.ts b/src/tribler/ui/src/services/tribler.service.ts index 1d7846524b..19506c6adb 100644 --- a/src/tribler/ui/src/services/tribler.service.ts +++ b/src/tribler/ui/src/services/tribler.service.ts @@ -382,6 +382,7 @@ export class TriblerService { return (await this.http.put(`/recommender/clicked`, { query: query, chosen_index: results.findIndex((e) => e.infohash == clicked.infohash), + timestamp: Date.now(), results: results.map((x) => { return { infohash: x.infohash, seeders: x.num_seeders,