Make db updates more robust again the sd card disappearing

Accidentally found a bug while live on youtube :)
custom
jacqueline 1 year ago
parent 299f3cc48f
commit 0f03efe868
  1. 23
      src/database/database.cpp
  2. 3
      src/database/file_gatherer.cpp

@ -274,12 +274,27 @@ auto Database::getIndexes() -> std::vector<IndexInfo> {
}; };
} }
class UpdateNotifier {
public:
UpdateNotifier(std::atomic<bool>& is_updating) : is_updating_(is_updating) {
events::Ui().Dispatch(event::UpdateStarted{});
events::System().Dispatch(event::UpdateStarted{});
}
~UpdateNotifier() {
is_updating_ = false;
events::Ui().Dispatch(event::UpdateFinished{});
events::System().Dispatch(event::UpdateFinished{});
}
private:
std::atomic<bool>& is_updating_;
};
auto Database::updateIndexes() -> void { auto Database::updateIndexes() -> void {
if (is_updating_.exchange(true)) { if (is_updating_.exchange(true)) {
return; return;
} }
events::Ui().Dispatch(event::UpdateStarted{}); UpdateNotifier notifier{is_updating_};
events::System().Dispatch(event::UpdateStarted{});
leveldb::ReadOptions read_options; leveldb::ReadOptions read_options;
read_options.fill_cache = false; read_options.fill_cache = false;
@ -453,10 +468,6 @@ auto Database::updateIndexes() -> void {
dbSetLastUpdate(newest_track); dbSetLastUpdate(newest_track);
ESP_LOGI(kTag, "newest track was at %u,%u", newest_track.first, ESP_LOGI(kTag, "newest track was at %u,%u", newest_track.first,
newest_track.second); newest_track.second);
is_updating_ = false;
events::Ui().Dispatch(event::UpdateFinished{});
events::System().Dispatch(event::UpdateFinished{});
} }
auto Database::isUpdating() -> bool { auto Database::isUpdating() -> bool {

@ -28,6 +28,8 @@ auto FileGathererImpl::FindFiles(
while (!to_explore.empty()) { while (!to_explore.empty()) {
std::string next_path_str = to_explore.front(); std::string next_path_str = to_explore.front();
to_explore.pop_front();
const TCHAR* next_path = static_cast<const TCHAR*>(next_path_str.c_str()); const TCHAR* next_path = static_cast<const TCHAR*>(next_path_str.c_str());
FF_DIR dir; FF_DIR dir;
@ -72,7 +74,6 @@ auto FileGathererImpl::FindFiles(
auto lock = drivers::acquire_spi(); auto lock = drivers::acquire_spi();
f_closedir(&dir); f_closedir(&dir);
to_explore.pop_front();
} }
} }

Loading…
Cancel
Save