|
19 | 19 | #include <climits> |
20 | 20 | #include <string.h> |
21 | 21 | #include <stdio.h> |
| 22 | +#include <shared_mutex> |
22 | 23 |
|
23 | 24 |
|
24 | 25 | namespace gameanalytics |
@@ -1160,18 +1161,36 @@ namespace gameanalytics |
1160 | 1161 |
|
1161 | 1162 | json GAState::getRemoteConfigAnnotations() |
1162 | 1163 | { |
1163 | | - json configs; |
1164 | | - for(json& obj : _configurations) |
1165 | | - { |
1166 | | - json cfg; |
1167 | | - cfg["vsn"] = utilities::getOptionalValue<int>(obj, "vsn", 0); |
1168 | | - cfg["key"] = utilities::getOptionalValue<std::string>(obj, "key", ""); |
1169 | | - cfg["id"] = utilities::getOptionalValue<std::string>(obj, "id", ""); |
| 1164 | + static json cachedConfigsAnnotation; |
| 1165 | + static json lastConfigurations; |
| 1166 | + static std::shared_mutex configsMutex; |
1170 | 1167 |
|
1171 | | - configs.push_back(cfg); |
| 1168 | + { |
| 1169 | + std::shared_lock lock(configsMutex); |
| 1170 | + if (_configurations == lastConfigurations) { |
| 1171 | + return cachedConfigsAnnotation; |
| 1172 | + } |
1172 | 1173 | } |
1173 | 1174 |
|
1174 | | - return configs; |
| 1175 | + { |
| 1176 | + std::unique_lock lock(configsMutex); |
| 1177 | + if (_configurations != lastConfigurations) { |
| 1178 | + cachedConfigsAnnotation = json::array(); |
| 1179 | + for (json& obj : _configurations) { |
| 1180 | + json cfg; |
| 1181 | + cfg["vsn"] = utilities::getOptionalValue<int>(obj, "vsn", 0); |
| 1182 | + |
| 1183 | + if (cfg["vsn"] == 0) continue; |
| 1184 | + |
| 1185 | + cfg["key"] = utilities::getOptionalValue<std::string>(obj, "key", ""); |
| 1186 | + cfg["id"] = utilities::getOptionalValue<std::string>(obj, "id", ""); |
| 1187 | + |
| 1188 | + cachedConfigsAnnotation.push_back(cfg); |
| 1189 | + } |
| 1190 | + lastConfigurations = _configurations; |
| 1191 | + } |
| 1192 | + return cachedConfigsAnnotation; |
| 1193 | + } |
1175 | 1194 | } |
1176 | 1195 | } |
1177 | 1196 | } |
0 commit comments