@@ -68,16 +68,17 @@ def create_crawl_query_info(query_id: int) -> dict:
68
68
}
69
69
70
70
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 :
72
72
"""
73
73
A response with the number of available results for the query with the id ``query_id``.
74
74
"""
75
75
return {
76
- "version" : 0 ,
76
+ "version" : 1 ,
77
77
"type" : "query_info" ,
78
78
"query_id" : query_id ,
79
79
"results" : results ,
80
80
"chosen_index" : chosen_index ,
81
+ "timestamp" : timestamp ,
81
82
"query" : query
82
83
}
83
84
@@ -176,7 +177,8 @@ def process_query_info(self, peer: Peer, request: dict) -> None:
176
177
query_id = query .rowid ,
177
178
results = len (unpacked ["results" ]),
178
179
chosen_index = unpacked ["chosen_index" ],
179
- query = unpacked ["query" ]
180
+ timestamp = unpacked .get ("timestamp" , 0 ),
181
+ query = unpacked ["query" ],
180
182
)), b"" ))
181
183
182
184
@lazy_wrapper (Crawl )
@@ -220,6 +222,7 @@ def __init__(self, request_cache: RequestCache, peer: Peer, response: dict) -> N
220
222
self .total_results = response ["results" ]
221
223
self .results : list [ResultItem | None ] = [None ] * self .total_results
222
224
self .chosen_index = response ["chosen_index" ]
225
+ self .timestamp = response .get ("timestamp" , 0 )
223
226
self .query = response ["query" ]
224
227
225
228
def get_next_range (self ) -> tuple [int , int ] | None :
@@ -300,14 +303,15 @@ def init_crawl_history(self) -> None:
300
303
self .crawl_history [peer_mid ] = (max_id , missing )
301
304
302
305
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 :
304
307
"""
305
308
Update self.crawl_history and write the results to a file.
306
309
"""
307
310
query_dir = os .path .join (self .crawl_directory , hexlify (peer .mid ).decode ())
308
311
os .makedirs (query_dir , exist_ok = True )
309
312
json_dict = {
310
313
"query" : query ,
314
+ "timestamp" : timestamp ,
311
315
"chosen_index" : chosen_index ,
312
316
"results" : results
313
317
}
@@ -356,7 +360,7 @@ def process_query_info_response(self, peer: Peer, response: dict) -> None:
356
360
357
361
if next_range is None :
358
362
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 , [])
360
364
else :
361
365
self .request_cache .add (cache )
362
366
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:
375
379
376
380
if next_range is None :
377
381
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 ,
379
383
cast (list [ResultItem ] , cache .results ))
380
384
else :
381
385
self .request_cache .add (cache ) # Reset the two-minute timer
0 commit comments