From 231fc30e13775a997cdecfe7ee990f693e75de72 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 23 Dec 2011 17:16:14 +0000 Subject: [PATCH] postpone recalculate auto-managed torrents when changing many torrents state --- src/session_impl.cpp | 2 +- src/torrent.cpp | 29 ++++++++++------------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index a02881f3f..c12b8a1ea 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4510,7 +4510,7 @@ namespace aux { // a boat load of torrents, we postpone the recalculation until // we're done adding them all (since it's kind of an expensive operation) if (params.flags & add_torrent_params::flag_auto_managed) - m_auto_manage_time_scaler = 1; + m_auto_manage_time_scaler = 2; return torrent_handle(torrent_ptr); } diff --git a/src/torrent.cpp b/src/torrent.cpp index 6f444fe33..c31bbc72d 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5908,8 +5908,8 @@ ctx->set_verify_callback(verify_function, ec); // this torrent just completed downloads, which means it will fall // under a different limit with the auto-manager. Make sure we // update auto-manage torrents in that case - if (m_auto_managed && m_ses.m_auto_manage_time_scaler > 1) - m_ses.m_auto_manage_time_scaler = 1; + if (m_auto_managed) + m_ses.m_auto_manage_time_scaler = 2; } // this is called when we were finished, but some files were @@ -6015,19 +6015,14 @@ ctx->set_verify_callback(verify_function, ec); // if this is an auto managed torrent, force a recalculation // of which torrents to have active - if (m_auto_managed && m_ses.m_auto_manage_time_scaler > 1) - m_ses.m_auto_manage_time_scaler = 1; + if (m_auto_managed) + m_ses.m_auto_manage_time_scaler = 2; if (!is_seed()) { // turn off super seeding if we're not a seed if (m_super_seeding) m_super_seeding = false; - // if we just finished checking and we're not a seed, we are - // likely to be unpaused - if (m_ses.m_auto_manage_time_scaler > 1) - m_ses.m_auto_manage_time_scaler = 1; - if (is_finished() && m_state != torrent_status::finished) finished(); } @@ -6410,8 +6405,7 @@ ctx->set_verify_callback(verify_function, ec); m_sequence_number = (std::min)(max_seq, p); } - if (m_ses.m_auto_manage_time_scaler > 2) - m_ses.m_auto_manage_time_scaler = 2; + m_ses.m_auto_manage_time_scaler = 2; } void torrent::set_max_uploads(int limit) @@ -6536,8 +6530,7 @@ ctx->set_verify_callback(verify_function, ec); TORRENT_ASSERT(m_ses.is_network_thread()); if (!m_error) return; bool checking_files = should_check_files(); - if (m_ses.m_auto_manage_time_scaler > 2) - m_ses.m_auto_manage_time_scaler = 2; + m_ses.m_auto_manage_time_scaler = 2; m_error = error_code(); m_error_file.clear(); @@ -6602,7 +6595,7 @@ ctx->set_verify_callback(verify_function, ec); // recalculate which torrents should be // paused - m_ses.m_auto_manage_time_scaler = 0; + m_ses.m_auto_manage_time_scaler = 2; if (!checking_files && should_check_files()) { @@ -6618,9 +6611,8 @@ ctx->set_verify_callback(verify_function, ec); // if this torrent is running and just became auto-managed // we might want to pause it in favor of some other torrent - if (m_auto_managed && !is_paused() - && m_ses.m_auto_manage_time_scaler > 1) - m_ses.m_auto_manage_time_scaler = 1; + if (m_auto_managed && !is_paused()) + m_ses.m_auto_manage_time_scaler = 2; } // the higher seed rank, the more important to seed @@ -6884,8 +6876,7 @@ ctx->set_verify_callback(verify_function, ec); // if this torrent was just paused // we might have to resume some other auto-managed torrent - if (m_ses.m_auto_manage_time_scaler > 1) - m_ses.m_auto_manage_time_scaler = 1; + m_ses.m_auto_manage_time_scaler = 2; } #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING || defined TORRENT_LOGGING