Skip to content

Commit

Permalink
Optimize checking for outdated tracker endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
glassez committed Nov 4, 2024
1 parent b083029 commit 91c5be4
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/base/bittorrent/torrentimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,6 @@ namespace

trackerEntryStatus.tier = nativeEntry.tier;

// remove outdated endpoints
trackerEntryStatus.endpoints.removeIf([&nativeEntry](const QHash<std::pair<QString, int>, TrackerEndpointStatus>::iterator &iter)
{
return std::none_of(nativeEntry.endpoints.cbegin(), nativeEntry.endpoints.cend()
, [&endpointName = std::get<0>(iter.key())](const auto &existingEndpoint)
{
return (endpointName == toString(existingEndpoint.local_endpoint));
});
});

const auto numEndpoints = static_cast<qsizetype>(nativeEntry.endpoints.size()) * btProtocols.size();

int numUpdating = 0;
Expand Down Expand Up @@ -205,6 +195,19 @@ namespace
}
}

if (trackerEntryStatus.endpoints.size() > numEndpoints)
{
// remove outdated endpoints
trackerEntryStatus.endpoints.removeIf([&nativeEntry](const QHash<std::pair<QString, int>, TrackerEndpointStatus>::iterator &iter)
{
return std::none_of(nativeEntry.endpoints.cbegin(), nativeEntry.endpoints.cend()
, [&endpointName = std::get<0>(iter.key())](const auto &existingEndpoint)
{
return (endpointName == toString(existingEndpoint.local_endpoint));
});
});
}

if (numEndpoints > 0)
{
if (numUpdating > 0)
Expand Down

0 comments on commit 91c5be4

Please sign in to comment.