Skip to content

Commit 0e9c1de

Browse files
committed
remove old configs from annotations
1 parent d76234d commit 0e9c1de

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

source/gameanalytics/GAState.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <climits>
2020
#include <string.h>
2121
#include <stdio.h>
22+
#include <shared_mutex>
2223

2324

2425
namespace gameanalytics
@@ -1160,18 +1161,36 @@ namespace gameanalytics
11601161

11611162
json GAState::getRemoteConfigAnnotations()
11621163
{
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;
11701167

1171-
configs.push_back(cfg);
1168+
{
1169+
std::shared_lock lock(configsMutex);
1170+
if (_configurations == lastConfigurations) {
1171+
return cachedConfigsAnnotation;
1172+
}
11721173
}
11731174

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+
}
11751194
}
11761195
}
11771196
}

0 commit comments

Comments
 (0)