@@ -6,125 +6,161 @@ std::optional<EngineEntry> DatabaseService::UpsertEngine(
6
6
const std::string& api_key, const std::string& url,
7
7
const std::string& version, const std::string& variant,
8
8
const std::string& status, const std::string& metadata) {
9
+ std::lock_guard<std::mutex> l (mtx_);
9
10
return cortex::db::Engines ().UpsertEngine (engine_name, type, api_key, url,
10
11
version, variant, status, metadata);
11
12
}
12
13
13
14
std::optional<std::vector<EngineEntry>> DatabaseService::GetEngines () const {
15
+ std::lock_guard<std::mutex> l (mtx_);
14
16
return cortex::db::Engines ().GetEngines ();
15
17
}
16
18
17
19
std::optional<EngineEntry> DatabaseService::GetEngineById (int id) const {
20
+ std::lock_guard<std::mutex> l (mtx_);
18
21
return cortex::db::Engines ().GetEngineById (id);
19
22
}
20
23
21
24
std::optional<EngineEntry> DatabaseService::GetEngineByNameAndVariant (
22
25
const std::string& engine_name,
23
26
const std::optional<std::string> variant) const {
27
+ std::lock_guard<std::mutex> l (mtx_);
24
28
return cortex::db::Engines ().GetEngineByNameAndVariant (engine_name, variant);
25
29
}
26
30
27
31
std::optional<std::string> DatabaseService::DeleteEngineById (int id) {
32
+ std::lock_guard<std::mutex> l (mtx_);
28
33
return cortex::db::Engines ().DeleteEngineById (id);
29
34
}
30
35
// end engines
31
36
32
37
// begin file
33
38
cpp::result<std::vector<OpenAi::File>, std::string>
34
39
DatabaseService::GetFileList () const {
40
+ std::lock_guard<std::mutex> l (mtx_);
35
41
return cortex::db::File ().GetFileList ();
36
42
}
37
43
38
44
cpp::result<OpenAi::File, std::string> DatabaseService::GetFileById (
39
45
const std::string& file_id) const {
46
+ std::lock_guard<std::mutex> l (mtx_);
40
47
return cortex::db::File ().GetFileById (file_id);
41
48
}
42
49
43
50
cpp::result<void , std::string> DatabaseService::AddFileEntry (
44
51
OpenAi::File& file) {
52
+ std::lock_guard<std::mutex> l (mtx_);
45
53
return cortex::db::File ().AddFileEntry (file);
46
54
}
47
55
48
56
cpp::result<void , std::string> DatabaseService::DeleteFileEntry (
49
57
const std::string& file_id) {
58
+ std::lock_guard<std::mutex> l (mtx_);
50
59
return cortex::db::File ().DeleteFileEntry (file_id);
51
60
}
52
61
// end file
53
62
54
63
// begin hardware
55
64
cpp::result<std::vector<HardwareEntry>, std::string>
56
65
DatabaseService::LoadHardwareList () const {
66
+ std::lock_guard<std::mutex> l (mtx_);
57
67
return cortex::db::Hardware ().LoadHardwareList ();
58
68
}
59
69
60
70
cpp::result<bool , std::string> DatabaseService::AddHardwareEntry (
61
71
const HardwareEntry& new_entry) {
72
+ std::lock_guard<std::mutex> l (mtx_);
62
73
return cortex::db::Hardware ().AddHardwareEntry (new_entry);
63
74
}
64
75
76
+ bool DatabaseService::HasHardwareEntry (const std::string& id) {
77
+ std::lock_guard<std::mutex> l (mtx_);
78
+ return cortex::db::Hardware ().HasHardwareEntry (id);
79
+ }
80
+
65
81
cpp::result<bool , std::string> DatabaseService::UpdateHardwareEntry (
66
82
const std::string& id, const HardwareEntry& updated_entry) {
83
+ std::lock_guard<std::mutex> l (mtx_);
67
84
return cortex::db::Hardware ().UpdateHardwareEntry (id, updated_entry);
68
85
}
69
86
70
87
cpp::result<bool , std::string> DatabaseService::DeleteHardwareEntry (
71
88
const std::string& id) {
89
+ std::lock_guard<std::mutex> l (mtx_);
72
90
return cortex::db::Hardware ().DeleteHardwareEntry (id);
73
91
}
92
+
93
+ cpp::result<bool , std::string> DatabaseService::UpdateHardwareEntry (
94
+ const std::string& id, int hw_id, int sw_id) const {
95
+ std::lock_guard<std::mutex> l (mtx_);
96
+ return cortex::db::Hardware ().UpdateHardwareEntry (id, hw_id, sw_id);
97
+ }
74
98
// end hardware
75
99
76
100
// begin models
77
101
cpp::result<std::vector<ModelEntry>, std::string>
78
102
DatabaseService::LoadModelList () const {
103
+ std::lock_guard<std::mutex> l (mtx_);
79
104
return cortex::db::Models ().LoadModelList ();
80
105
}
81
106
82
107
cpp::result<ModelEntry, std::string> DatabaseService::GetModelInfo (
83
108
const std::string& identifier) const {
109
+ std::lock_guard<std::mutex> l (mtx_);
84
110
return cortex::db::Models ().GetModelInfo (identifier);
85
111
}
86
112
87
113
cpp::result<bool , std::string> DatabaseService::AddModelEntry (
88
114
ModelEntry new_entry) {
115
+ std::lock_guard<std::mutex> l (mtx_);
89
116
return cortex::db::Models ().AddModelEntry (new_entry);
90
117
}
91
118
92
119
cpp::result<bool , std::string> DatabaseService::UpdateModelEntry (
93
120
const std::string& identifier, const ModelEntry& updated_entry) {
121
+ std::lock_guard<std::mutex> l (mtx_);
94
122
return cortex::db::Models ().UpdateModelEntry (identifier, updated_entry);
95
123
}
96
124
97
125
cpp::result<bool , std::string> DatabaseService::DeleteModelEntry (
98
126
const std::string& identifier) {
127
+ std::lock_guard<std::mutex> l (mtx_);
99
128
return cortex::db::Models ().DeleteModelEntry (identifier);
100
129
}
101
130
102
131
cpp::result<bool , std::string> DatabaseService::DeleteModelEntryWithOrg (
103
132
const std::string& src) {
133
+ std::lock_guard<std::mutex> l (mtx_);
104
134
return cortex::db::Models ().DeleteModelEntryWithOrg (src);
105
135
}
106
136
107
137
cpp::result<bool , std::string> DatabaseService::DeleteModelEntryWithRepo (
108
138
const std::string& src) {
139
+
140
+ std::lock_guard<std::mutex> l (mtx_);
109
141
return cortex::db::Models ().DeleteModelEntryWithRepo (src);
110
142
}
111
143
112
144
cpp::result<std::vector<std::string>, std::string>
113
145
DatabaseService::FindRelatedModel (const std::string& identifier) const {
146
+ std::lock_guard<std::mutex> l (mtx_);
114
147
return cortex::db::Models ().FindRelatedModel (identifier);
115
148
}
116
149
117
150
bool DatabaseService::HasModel (const std::string& identifier) const {
151
+ std::lock_guard<std::mutex> l (mtx_);
118
152
return cortex::db::Models ().HasModel (identifier);
119
153
}
120
154
121
155
cpp::result<std::vector<ModelEntry>, std::string> DatabaseService::GetModels (
122
156
const std::string& model_src) const {
157
+ std::lock_guard<std::mutex> l (mtx_);
123
158
return cortex::db::Models ().GetModels (model_src);
124
159
}
125
160
126
161
cpp::result<std::vector<ModelEntry>, std::string>
127
162
DatabaseService::GetModelSources () const {
163
+ std::lock_guard<std::mutex> l (mtx_);
128
164
return cortex::db::Models ().GetModelSources ();
129
165
}
130
166
// end models
0 commit comments