Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit fe3f051

Browse files
committed
fix: use map to save data
1 parent df9232a commit fe3f051

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

engine/services/model_source_service.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,21 @@ cpp::result<ModelSource, std::string> ModelSourceService::GetModelSource(
199199
return ms;
200200
}
201201

202-
203202
cpp::result<std::vector<std::string>, std::string>
204203
ModelSourceService::GetRepositoryList(std::string_view author) {
205-
if (!cortexso_repos_.empty())
206-
return cortexso_repos_;
204+
std::string as(author);
205+
if (cortexso_repos_.find(as) != cortexso_repos_.end() &&
206+
!cortexso_repos_.at(as).empty())
207+
return cortexso_repos_.at(as);
207208
const auto begin = std::chrono::high_resolution_clock::now();
208-
auto res = curl_utils::SimpleGet("https://huggingface.co/api/models?author=" +
209-
std::string(author));
209+
auto res =
210+
curl_utils::SimpleGet("https://huggingface.co/api/models?author=" + as);
210211
if (res.has_value()) {
211212
auto repos = ParseJsonString(res.value());
212213
for (auto& r : repos) {
213-
cortexso_repos_.push_back(r.id);
214+
cortexso_repos_[as].push_back(r.id);
214215
}
215-
return cortexso_repos_;
216+
return cortexso_repos_.at(as);
216217
} else {
217218
return cpp::fail(res.error());
218219
}

engine/services/model_source_service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ class ModelSourceService {
8989
std::thread sync_db_thread_;
9090
std::atomic<bool> running_;
9191

92-
std::vector<std::string> cortexso_repos_;
92+
std::unordered_map<std::string, std::vector<std::string>> cortexso_repos_;
9393
};

0 commit comments

Comments
 (0)