From a3fe981daa117e17fc1f9d90b680ceea0051d5f3 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Fri, 1 Oct 2021 15:07:09 +0330 Subject: [PATCH] RequestServer: Ignore preconnect requests for available connections There's no need to schedule a useless job when the connection is already there and established. --- Userland/Services/RequestServer/ClientConnection.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Userland/Services/RequestServer/ClientConnection.cpp b/Userland/Services/RequestServer/ClientConnection.cpp index c703350349..75762628e6 100644 --- a/Userland/Services/RequestServer/ClientConnection.cpp +++ b/Userland/Services/RequestServer/ClientConnection.cpp @@ -138,8 +138,7 @@ void ClientConnection::ensure_connection(URL const& url, ::RequestServer::CacheL if (!is_tls && socket->is_connected()) is_connected = true; - if (is_connected) - return ConnectionCache::request_did_finish(m_url, socket); + VERIFY(!is_connected); bool did_connect; if (is_tls) { @@ -167,7 +166,9 @@ void ClientConnection::ensure_connection(URL const& url, ::RequestServer::CacheL dbgln("EnsureConnection: Pre-connect to {}", url); auto do_preconnect = [&](auto& cache) { - ConnectionCache::get_or_create_connection(cache, url, job); + auto it = cache.find({ url.host(), url.port_or_default() }); + if (it == cache.end() || it->value->is_empty()) + ConnectionCache::get_or_create_connection(cache, url, job); }; if (url.scheme() == "http"sv)