@@ -68,16 +68,17 @@ def create_crawl_query_info(query_id: int) -> dict:
6868 }
6969
7070
71- def create_crawl_query_info_response (query_id : int , results : int , chosen_index : int , query : str ) -> dict :
71+ def create_crawl_query_info_response (query_id : int , timestamp : int , results : int , chosen_index : int , query : str ) -> dict :
7272 """
7373 A response with the number of available results for the query with the id ``query_id``.
7474 """
7575 return {
76- "version" : 0 ,
76+ "version" : 1 ,
7777 "type" : "query_info" ,
7878 "query_id" : query_id ,
7979 "results" : results ,
8080 "chosen_index" : chosen_index ,
81+ "timestamp" : timestamp ,
8182 "query" : query
8283 }
8384
@@ -176,7 +177,8 @@ def process_query_info(self, peer: Peer, request: dict) -> None:
176177 query_id = query .rowid ,
177178 results = len (unpacked ["results" ]),
178179 chosen_index = unpacked ["chosen_index" ],
179- query = unpacked ["query" ]
180+ timestamp = unpacked .get ("timestamp" , 0 ),
181+ query = unpacked ["query" ],
180182 )), b"" ))
181183
182184 @lazy_wrapper (Crawl )
@@ -220,6 +222,7 @@ def __init__(self, request_cache: RequestCache, peer: Peer, response: dict) -> N
220222 self .total_results = response ["results" ]
221223 self .results : list [ResultItem | None ] = [None ] * self .total_results
222224 self .chosen_index = response ["chosen_index" ]
225+ self .timestamp = response .get ("timestamp" , 0 )
223226 self .query = response ["query" ]
224227
225228 def get_next_range (self ) -> tuple [int , int ] | None :
@@ -300,14 +303,15 @@ def init_crawl_history(self) -> None:
300303 self .crawl_history [peer_mid ] = (max_id , missing )
301304
302305 def finalize_query (self , peer : Peer , query_id : int , query : str , chosen_index : int ,
303- results : list [ResultItem ]) -> None :
306+ timestamp : int , results : list [ResultItem ]) -> None :
304307 """
305308 Update self.crawl_history and write the results to a file.
306309 """
307310 query_dir = os .path .join (self .crawl_directory , hexlify (peer .mid ).decode ())
308311 os .makedirs (query_dir , exist_ok = True )
309312 json_dict = {
310313 "query" : query ,
314+ "timestamp" : timestamp ,
311315 "chosen_index" : chosen_index ,
312316 "results" : results
313317 }
@@ -356,7 +360,7 @@ def process_query_info_response(self, peer: Peer, response: dict) -> None:
356360
357361 if next_range is None :
358362 self .logger .info ("Query %d is empty for %s." , response ["query_id" ], str (peer ))
359- self .finalize_query (peer , cache .query_id , cache .query , cache .chosen_index , [])
363+ self .finalize_query (peer , cache .query_id , cache .query , cache .chosen_index , cache . timestamp , [])
360364 else :
361365 self .request_cache .add (cache )
362366 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:
375379
376380 if next_range is None :
377381 self .logger .info ("Query %d has completed for %s." , response ["query_id" ], str (peer ))
378- self .finalize_query (peer , cache .query_id , cache .query , cache .chosen_index ,
382+ self .finalize_query (peer , cache .query_id , cache .query , cache .chosen_index , cache . timestamp ,
379383 cast (list [ResultItem ] , cache .results ))
380384 else :
381385 self .request_cache .add (cache ) # Reset the two-minute timer
0 commit comments