Optimize checking for outdated tracker endpoints

PR #21768.
This commit is contained in:
Vladimir Golovnev 2024-11-07 09:40:33 +03:00 committed by GitHub
parent 4527536858
commit a6c7aef6c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -115,16 +115,6 @@ namespace
trackerEntryStatus.tier = nativeEntry.tier; 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(); const auto numEndpoints = static_cast<qsizetype>(nativeEntry.endpoints.size()) * btProtocols.size();
int numUpdating = 0; int numUpdating = 0;
@ -207,6 +197,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 (numEndpoints > 0)
{ {
if (numUpdating > 0) if (numUpdating > 0)