From 87f1f6ace074c7c974053af1a0129a9b873368f9 Mon Sep 17 00:00:00 2001 From: routersys Date: Thu, 10 Sep 2026 11:28:23 +0900 Subject: [PATCH] =?UTF-8?q?=E7=B4=A0=E6=9D=90=E3=81=AE=E5=88=A4=E5=AE=9A?= =?UTF-8?q?=E3=82=92=E8=A6=9A=E3=81=88=E3=81=A6=E5=95=8F=E3=81=84=E5=90=88?= =?UTF-8?q?=E3=82=8F=E3=81=9B=E3=82=92=E7=9C=81=E3=81=8F=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ScanController.cpp | 45 ++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/ScanController.cpp b/src/ScanController.cpp index f02038f..b6c294e 100644 --- a/src/ScanController.cpp +++ b/src/ScanController.cpp @@ -31,6 +31,13 @@ std::thread g_worker; std::mutex g_wake_lock; std::condition_variable g_wake; +struct Decision { + std::wstring proxy; + long long size = 0; + long long time = 0; +}; +std::map g_decisions; + std::string ToUtf8(const std::wstring& text) { if (text.empty()) return std::string(); int length = WideCharToMultiByte(CP_UTF8, 0, text.c_str(), (int)text.size(), nullptr, 0, nullptr, @@ -191,22 +198,34 @@ ScanResult ApplyProxies() { auto cached = resolved.find(path); if (cached == resolved.end()) { - MediaQuery query; - query.path = path; - CallReadSection(&query, QueryMedia); - if (!query.ok || !Eligible(path, query.info)) { - resolved[path] = std::wstring(); + SourceKey key; + const bool present = QuerySource(path, key); + auto remembered = g_decisions.find(path); + if (present && remembered != g_decisions.end() && + remembered->second.size == key.size && remembered->second.time == key.time) { + resolved[path] = remembered->second.proxy; + if (!remembered->second.proxy.empty()) RegisterSource(path, resolved[path]); + cached = resolved.find(path); + } else { + MediaQuery query; + query.path = path; + CallReadSection(&query, QueryMedia); + std::wstring proxy; + if (!query.ok || !Eligible(path, query.info) || !RegisterSource(path, proxy)) { + proxy.clear(); + } + resolved[path] = proxy; + Decision decision; + decision.proxy = proxy; + decision.size = key.size; + decision.time = key.time; + if (present) g_decisions[path] = decision; + cached = resolved.find(path); + } + if (cached->second.empty()) { result.rejected++; continue; } - std::wstring proxy; - if (!RegisterSource(path, proxy)) { - resolved[path] = std::wstring(); - result.rejected++; - continue; - } - resolved[path] = proxy; - cached = resolved.find(path); } if (cached->second.empty()) continue; result.eligible++;