Commit 82f02675 authored by Michael Ott's avatar Michael Ott
Browse files

Rework loadCache() to accelerate getPublicSensorsByWildcard() calls

parent dfe95445
......@@ -49,9 +49,9 @@ protected:
Connection* connection;
CassSession* session;
typedef std::unordered_map<std::string, std::reference_wrapper<PublicSensor>> SensorMap_t;
typedef std::unordered_map<std::string, PublicSensor> SensorMap_t;
SensorMap_t sensorMapByName;
std::list<PublicSensor> sensorList;
std::list<std::string> sensorList;
bool validateSensorPattern(const char* sensorPattern);
bool validateSensorPublicName(std::string publicName);
......
......@@ -306,17 +306,17 @@ bool SensorConfigImpl::validateSensorPublicName(std::string publicName)
SCError SensorConfigImpl::loadCache()
{
sensorList.clear();
sensorMapByName.clear();
SCError rc = getPublicSensorsVerbose(sensorList);
if (rc != SC_OK) {
return rc;
if (sensorList.size() != 0) {
return SC_OK;
} else {
for (auto& s: sensorList) {
sensorMapByName.insert(std::make_pair(s.name, std::ref(s)));
}
return SC_OK;
#ifdef DEBUG
TimeStamp ts;
#endif
SCError ret = getPublicSensorNames(sensorList);
#ifdef DEBUG
std::cerr << "loadCache: " << sensorList.size() << " sensors loaded in " << TimeStamp().getRaw() - ts.getRaw() << " ns" << std::endl;
#endif
return ret;
}
}
......@@ -1063,9 +1063,8 @@ SCError SensorConfigImpl::getPublicSensorByName(PublicSensor& sensor, const char
sensor.ttl = ttl;
sensor.operations = operations;
/* Add to sensorPropertyCache for later use */
sensorList.push_back(sensor);
sensorMapByName.insert(std::make_pair(publicName, std::ref(sensorList.back())));
/* Add to sensorMap for later use */
sensorMapByName.insert(std::make_pair(publicName, sensor));
}
else {
cass_result_free(result);
......@@ -1096,8 +1095,7 @@ SCError SensorConfigImpl::getPublicSensorsByWildcard(std::list<PublicSensor>& se
}
return err;
} else {
std::list<std::string> sensorNames;
if ((err = getPublicSensorNames(sensorNames)) == SC_OK) {
if (loadCache() == SC_OK) {
std::string w("^");
while (*wildcard != 0) {
switch (*wildcard) {
......@@ -1123,7 +1121,7 @@ SCError SensorConfigImpl::getPublicSensorsByWildcard(std::list<PublicSensor>& se
}
boost::regex r(w, boost::regex::basic);
for (auto s: sensorNames) {
for (auto s: sensorList) {
if (boost::regex_match(s, r)) {
PublicSensor ps;
getPublicSensorByName(ps, s.c_str());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment