Adding proper serial number cache for quick search

This commit is contained in:
stephb9959
2022-04-05 08:31:31 -07:00
parent 59b752aa92
commit 65467b7320
2 changed files with 31 additions and 0 deletions

View File

@@ -75,6 +75,8 @@ namespace OpenWifi {
EntityDB_->CheckForRoot();
InventoryDB_->InitializeSerialCache();
ConsistencyCheck();
TimerCallback_ = std::make_unique<Poco::TimerCallback<Storage>>(*this,&Storage::onTimer);
Timer_.setStartInterval( 20 * 1000); // first run in 20 seconds
Timer_.setPeriodicInterval(1 * 60 * 60 * 1000); // 1 hours
@@ -169,6 +171,33 @@ namespace OpenWifi {
return true;
}
void Storage::ConsistencyCheck() {
// check that all inventory in venues and entities actually exists, if not, fix it.
std::cout << "Fixing: venues..." << std::endl;
auto FixVenueDevices = [&](const ProvObjects::Venue &V) -> bool {
Types::UUIDvec_t NewDevices;
for(const auto &device:V.devices) {
ProvObjects::InventoryTag T;
if(InventoryDB().GetRecord("id", device, T)) {
NewDevices.emplace_back(device);
}
}
if(NewDevices!=V.devices) {
std::cout << "Fixing venue: " << V.info.name << std::endl;
// ProvObjects::Venue NewVenue = V;
// NewVenue.devices = NewDevices;
// VenueDB().UpdateRecord("id", V.info.id, NewVenue);
}
return true;
};
VenueDB().Iterate(FixVenueDevices);
}
}
// namespace