mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 02:35:31 +00:00
aquatic_ws: in scrape handler, limit HashMap preallocation
This commit is contained in:
parent
9a04173f65
commit
1a2432733e
1 changed files with 5 additions and 5 deletions
|
|
@ -218,17 +218,17 @@ pub fn handle_scrape_requests(
|
||||||
requests: Drain<(ConnectionMeta, ScrapeRequest)>,
|
requests: Drain<(ConnectionMeta, ScrapeRequest)>,
|
||||||
){
|
){
|
||||||
messages_out.extend(requests.map(|(meta, request)| {
|
messages_out.extend(requests.map(|(meta, request)| {
|
||||||
let num_info_hashes = request.info_hashes.len();
|
let num_to_take = request.info_hashes.len().min(
|
||||||
|
config.network.max_scrape_torrents
|
||||||
|
);
|
||||||
|
|
||||||
let mut response = ScrapeResponse {
|
let mut response = ScrapeResponse {
|
||||||
files: HashMap::with_capacity(num_info_hashes),
|
files: HashMap::with_capacity(num_to_take),
|
||||||
};
|
};
|
||||||
|
|
||||||
let max_torrents = config.network.max_scrape_torrents;
|
|
||||||
|
|
||||||
// If request.info_hashes is empty, don't return scrape for all
|
// If request.info_hashes is empty, don't return scrape for all
|
||||||
// torrents, even though reference server does it. It is too expensive.
|
// torrents, even though reference server does it. It is too expensive.
|
||||||
for info_hash in request.info_hashes.into_iter().take(max_torrents){
|
for info_hash in request.info_hashes.into_iter().take(num_to_take){
|
||||||
if let Some(torrent_data) = torrents.get(&info_hash){
|
if let Some(torrent_data) = torrents.get(&info_hash){
|
||||||
let stats = ScrapeStatistics {
|
let stats = ScrapeStatistics {
|
||||||
complete: torrent_data.num_seeders,
|
complete: torrent_data.num_seeders,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue