mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-20 14:08:20 +00:00
Fetch cloud plugin metadata faster (#16645)
When logged in to Orca Cloud, the plugin fetch at startup no longer refreshes the token a second time while start() is already refreshing it. It now waits for that refresh and checks the token again. The subscribed and owned plugin requests also run in parallel, so the fetch takes about half as long.
This commit is contained in:
3 files changed
+83
-16
No files matched your search
@@ -1917,13 +1917,20 @@ RefreshResult OrcaCloudServiceAgent::refresh_from_storage(const std::string& rea
|
||||
|
||||
bool OrcaCloudServiceAgent::refresh_if_expiring(std::chrono::seconds skew, const std::string& reason)
|
||||
{
|
||||
bool needs_refresh = false;
|
||||
{
|
||||
const auto needs_refresh = [&] {
|
||||
std::lock_guard<std::mutex> lock(session_mutex);
|
||||
needs_refresh = should_refresh_locked(skew);
|
||||
}
|
||||
return should_refresh_locked(skew);
|
||||
};
|
||||
if (!needs_refresh())
|
||||
return true;
|
||||
|
||||
if (!needs_refresh)
|
||||
// A refresh may already be running on another thread, e.g. the one start() launches. Wait for
|
||||
// it and check again instead of spending the refresh token it is rotating. Bounded: the
|
||||
// refresh POST times out after 30 s.
|
||||
const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(60);
|
||||
while (refresh_running.load() && std::chrono::steady_clock::now() < deadline)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
if (!needs_refresh())
|
||||
return true;
|
||||
|
||||
// First attempt. refresh_from_storage blocks on the cross-process lock and reads the
|
||||
@@ -1935,6 +1942,8 @@ bool OrcaCloudServiceAgent::refresh_if_expiring(std::chrono::seconds skew, const
|
||||
// One retry, only for a transient network failure of the refresh POST (lost response,
|
||||
// timeout, 429/5xx -> Transient). The retry re-acquires the lock and re-reads the store.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(750));
|
||||
if (!needs_refresh())
|
||||
return true;
|
||||
return refresh_from_storage(reason + "_retry", false) == RefreshResult::Success;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
#include <cstddef>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <ios>
|
||||
#include <slic3r/plugin/PluginDescriptor.hpp>
|
||||
@@ -49,16 +50,22 @@ bool CloudPluginService::fetch_manifests_into_descriptors(std::vector<PluginDesc
|
||||
unauthorized.clear();
|
||||
|
||||
if (m_orca_agent) {
|
||||
// Refresh the token once, then run both requests in parallel.
|
||||
m_orca_agent->ensure_token_fresh("fetch_plugin_manifests");
|
||||
std::vector<PluginDescriptor> mine_descriptors;
|
||||
auto mine = std::async(std::launch::async, [agent = m_orca_agent, &mine_descriptors] {
|
||||
return agent->fetch_mine_manifests_into_descriptors(mine_descriptors);
|
||||
});
|
||||
|
||||
int ret = m_orca_agent->fetch_subscribed_manifests_into_descriptors(descriptors, not_found, unauthorized);
|
||||
const int mine_ret = mine.get();
|
||||
|
||||
if (ret != 0) {
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": Failed to get subscribed plugins.";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<PluginDescriptor> mine_descriptors;
|
||||
|
||||
ret = m_orca_agent->fetch_mine_manifests_into_descriptors(mine_descriptors);
|
||||
ret = mine_ret;
|
||||
|
||||
if (ret != 0) {
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": Failed to get owned plugins.";
|
||||
|
||||
Reference in new issue
Block a user