MCPcopy Create free account
hub / github.com/Selectively11/CloudRedirect / SweepNamespaceSchemas

Function SweepNamespaceSchemas

src/platform/linux/schema_fetch.cpp:567–611  ·  view source on GitHub ↗

Proactive sweep.

Source from the content-addressed store, hash-verified

565
566// Proactive sweep.
567static void SweepNamespaceSchemas() {
568 if (!MetadataSync::SchemaFetchEnabled()) return;
569 if (g_connHandle.load(std::memory_order_relaxed) == 0) return;
570
571 auto apps = CloudIntercept::GetNamespaceApps();
572 if (apps.empty()) return;
573
574 LOG("[SchemaFetch] Proactive sweep: checking %zu namespace app(s)", apps.size());
575
576 std::string steamPath = CloudIntercept::GetSteamPath();
577 std::vector<uint32_t> needed;
578 for (uint32_t appId : apps) {
579 std::string path = steamPath + "appcache/stats/UserGameStatsSchema_"
580 + std::to_string(appId) + ".bin";
581 struct stat st;
582 if (stat(path.c_str(), &st) != 0 || st.st_size == 0) {
583 needed.push_back(appId);
584 }
585 }
586 if (needed.empty()) {
587 LOG("[SchemaFetch] All schemas present on disk");
588 return;
589 }
590
591 LOG("[SchemaFetch] %zu app(s) need schemas, fetching with 4 workers", needed.size());
592
593 constexpr int kWorkers = 4;
594 std::atomic<size_t> idx{0};
595 std::atomic<int> totalRequested{0};
596 std::vector<std::thread> workers;
597 for (int w = 0; w < kWorkers; ++w) {
598 workers.emplace_back([&needed, &idx, &totalRequested] {
599 while (true) {
600 if (g_shuttingDown.load(std::memory_order_acquire)) break;
601 size_t i = idx.fetch_add(1, std::memory_order_relaxed);
602 if (i >= needed.size()) break;
603 RequestSchemaForApp(needed[i]);
604 totalRequested.fetch_add(1, std::memory_order_relaxed);
605 }
606 });
607 }
608 for (auto& t : workers) t.join();
609 LOG("[SchemaFetch] Sweep complete: enqueued schemas for %d app(s)",
610 totalRequested.load(std::memory_order_relaxed));
611}
612
613static void MaybeScheduleSweep() {
614 if (!MetadataSync::SchemaFetchEnabled()) return;

Callers 1

MaybeScheduleSweepFunction · 0.70

Calls 6

SchemaFetchEnabledFunction · 0.85
sizeMethod · 0.80
GetNamespaceAppsFunction · 0.70
GetSteamPathFunction · 0.70
statClass · 0.70
RequestSchemaForAppFunction · 0.70

Tested by

no test coverage detected