refactor: remove tr_torrentStatCached() (#6066)

This commit is contained in:
Charles Kerr 2023-10-02 14:07:28 -05:00 committed by GitHub
parent 5808f72f50
commit 917c00e477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 2 additions and 23 deletions

View File

@ -626,7 +626,7 @@ void DetailsDialog::Impl::refreshInfo(std::vector<tr_torrent*> const& torrents)
infos.reserve(torrents.size());
for (auto* const torrent : torrents)
{
stats.push_back(tr_torrentStatCached(torrent));
stats.push_back(tr_torrentStat(torrent));
infos.push_back(tr_torrentView(torrent));
}

View File

@ -1441,14 +1441,7 @@ tr_stat const* tr_torrentStat(tr_torrent* tor)
auto const now = tr_time_msec();
auto const now_sec = tr_time();
auto swarm_stats = tr_swarm_stats{};
tor->lastStatTime = now_sec;
if (tor->swarm != nullptr)
{
swarm_stats = tr_swarmGetStats(tor->swarm);
}
auto const swarm_stats = tor->swarm != nullptr ? tr_swarmGetStats(tor->swarm) : tr_swarm_stats{};
tr_stat* const s = &tor->stats;
s->id = tor->id();
@ -1600,13 +1593,6 @@ tr_stat const* tr_torrentStat(tr_torrent* tor)
return s;
}
tr_stat const* tr_torrentStatCached(tr_torrent* tor)
{
time_t const now = tr_time();
return (tr_isTorrent(tor) && now == tor->lastStatTime) ? &tor->stats : tr_torrentStat(tor);
}
// ---
tr_file_view tr_torrentFile(tr_torrent const* tor, tr_file_index_t file)

View File

@ -875,8 +875,6 @@ public:
time_t editDate = 0;
time_t startDate = 0;
time_t lastStatTime = 0;
time_t seconds_downloading_before_current_start_ = 0;
time_t seconds_seeding_before_current_start_ = 0;

View File

@ -1610,11 +1610,6 @@ struct tr_stat
second or so to get a new snapshot of the torrent's status. */
tr_stat const* tr_torrentStat(tr_torrent* torrent);
/** Like `tr_torrentStat()`, but only recalculates the statistics if it's
been longer than a second since they were last calculated. This can
reduce the CPU load if you're calling `tr_torrentStat()` frequently. */
tr_stat const* tr_torrentStatCached(tr_torrent* torrent);
/** @} */
/** @brief Sanity checker to test that the direction is `TR_UP` or `TR_DOWN` */