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

Commit 0a9acb0

Browse files
committed
fix: get downloaded models
1 parent a3e3eb7 commit 0a9acb0

File tree

5 files changed

+21
-37
lines changed

5 files changed

+21
-37
lines changed

engine/database/models.cc

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -270,23 +270,6 @@ bool Models::HasModel(const std::string& identifier) const {
270270
}
271271
}
272272

273-
cpp::result<std::vector<std::string>, std::string> Models::GetModelSources()
274-
const {
275-
try {
276-
std::vector<std::string> sources;
277-
SQLite::Statement query(db_,
278-
"SELECT DISTINCT model_source FROM models WHERE "
279-
"status = \"downloadable\"");
280-
281-
while (query.executeStep()) {
282-
sources.push_back(query.getColumn(0).getString());
283-
}
284-
return sources;
285-
} catch (const std::exception& e) {
286-
return cpp::fail(e.what());
287-
}
288-
}
289-
290273
cpp::result<std::vector<ModelEntry>, std::string> Models::GetModels(
291274
const std::string& model_src) const {
292275
try {
@@ -318,16 +301,17 @@ cpp::result<std::vector<ModelEntry>, std::string> Models::GetModels(
318301
}
319302
}
320303

321-
cpp::result<std::vector<ModelEntry>, std::string>
322-
Models::GetDownloadableModels() const {
304+
cpp::result<std::vector<ModelEntry>, std::string> Models::GetModelSources()
305+
const {
323306
try {
324307
std::vector<ModelEntry> res;
325308
SQLite::Statement query(
326309
db_,
327310
"SELECT model_id, author_repo_id, branch_name, "
328311
"path_to_model_yaml, model_alias, model_format, "
329312
"model_source, status, engine, metadata FROM models "
330-
"WHERE status = \"downloadable\"");
313+
"WHERE model_source != \"\" AND (status = \"downloaded\" OR status = "
314+
"\"downloadable\")");
331315
while (query.executeStep()) {
332316
ModelEntry entry;
333317
entry.model = query.getColumn(0).getString();

engine/database/models.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ class Models {
5656
cpp::result<std::vector<std::string>, std::string> FindRelatedModel(
5757
const std::string& identifier) const;
5858
bool HasModel(const std::string& identifier) const;
59-
cpp::result<std::vector<std::string>, std::string> GetModelSources() const;
6059
cpp::result<std::vector<ModelEntry>, std::string> GetModels(
6160
const std::string& model_src) const;
62-
cpp::result<std::vector<ModelEntry>, std::string> GetDownloadableModels() const;
61+
cpp::result<std::vector<ModelEntry>, std::string> GetModelSources() const;
6362
};
6463

6564
} // namespace cortex::db

engine/services/database_service.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,13 @@ bool DatabaseService::HasModel(const std::string& identifier) const {
118118
return cortex::db::Models().HasModel(identifier);
119119
}
120120

121-
cpp::result<std::vector<std::string>, std::string>
122-
DatabaseService::GetModelSources() const {
123-
return cortex::db::Models().GetModelSources();
124-
}
125-
126121
cpp::result<std::vector<ModelEntry>, std::string> DatabaseService::GetModels(
127122
const std::string& model_src) const {
128123
return cortex::db::Models().GetModels(model_src);
129124
}
130125

131126
cpp::result<std::vector<ModelEntry>, std::string>
132-
DatabaseService::GetDownloadableModels() const {
133-
return cortex::db::Models().GetDownloadableModels();
127+
DatabaseService::GetModelSources() const {
128+
return cortex::db::Models().GetModelSources();
134129
}
135130
// end models

engine/services/database_service.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ class DatabaseService {
6060
cpp::result<std::vector<std::string>, std::string> FindRelatedModel(
6161
const std::string& identifier) const;
6262
bool HasModel(const std::string& identifier) const;
63-
cpp::result<std::vector<std::string>, std::string> GetModelSources() const;
6463
cpp::result<std::vector<ModelEntry>, std::string> GetModels(
6564
const std::string& model_src) const;
66-
cpp::result<std::vector<ModelEntry>, std::string> GetDownloadableModels()
65+
cpp::result<std::vector<ModelEntry>, std::string> GetModelSources()
6766
const;
6867

6968
private:

engine/services/model_source_service.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,14 @@ cpp::result<bool, std::string> ModelSourceService::RemoveModelSource(
113113
return cpp::fail(srcs.error());
114114
} else {
115115
auto& v = srcs.value();
116-
if (std::find(v.begin(), v.end(), model_source) == v.end()) {
116+
auto exists = [&v, &model_source]() {
117+
for (auto const& m : v) {
118+
if (m.model_source == model_source)
119+
return true;
120+
}
121+
return false;
122+
}();
123+
if (!exists) {
117124
return cpp::fail("Model source does not exist: " + model_source);
118125
}
119126
}
@@ -146,7 +153,7 @@ cpp::result<bool, std::string> ModelSourceService::RemoveModelSource(
146153

147154
cpp::result<std::unordered_map<std::string, ModelSource>, std::string>
148155
ModelSourceService::GetModelSources() {
149-
auto res = db_service_->GetDownloadableModels();
156+
auto res = db_service_->GetModelSources();
150157
if (res.has_error()) {
151158
return cpp::fail(res.error());
152159
}
@@ -476,18 +483,18 @@ void ModelSourceService::SyncModelSource() {
476483
CTL_INF(res.error());
477484
} else {
478485
for (auto const& src : res.value()) {
479-
CTL_DBG(src);
486+
CTL_DBG(src.model_source);
480487
}
481488

482489
std::unordered_set<std::string> orgs;
483490
std::vector<std::string> repos;
484491
for (auto const& src : res.value()) {
485-
auto url_res = url_parser::FromUrlString(src);
492+
auto url_res = url_parser::FromUrlString(src.model_source);
486493
if (url_res.has_value()) {
487494
if (url_res->pathParams.size() == 1) {
488-
orgs.insert(src);
495+
orgs.insert(src.model_source);
489496
} else if (url_res->pathParams.size() == 2) {
490-
repos.push_back(src);
497+
repos.push_back(src.model_source);
491498
}
492499
}
493500
}

0 commit comments

Comments
 (0)