From ee8e5234562c2b9ee1bb261785135abd4f718f83 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 4 Oct 2023 15:38:18 +1100 Subject: Add a basic database reindex screen --- src/database/database.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/database/database.cpp') diff --git a/src/database/database.cpp b/src/database/database.cpp index 1ecd72e0..ad81cfcf 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -136,14 +136,18 @@ auto Database::Update() -> std::future { // Stage 1: verify all existing tracks are still valid. ESP_LOGI(kTag, "verifying existing tracks"); - events::Ui().Dispatch(event::UpdateProgress{ - .stage = event::UpdateProgress::Stage::kVerifyingExistingTracks, - }); { + uint64_t num_processed = 0; std::unique_ptr it{db_->NewIterator(read_options)}; OwningSlice prefix = EncodeDataPrefix(); it->Seek(prefix.slice); while (it->Valid() && it->key().starts_with(prefix.slice)) { + num_processed++; + events::Ui().Dispatch(event::UpdateProgress{ + .stage = event::UpdateProgress::Stage::kVerifyingExistingTracks, + .val = num_processed, + }); + std::shared_ptr track = ParseDataValue(it->value()); if (!track) { // The value was malformed. Drop this record. @@ -195,10 +199,14 @@ auto Database::Update() -> std::future { // Stage 2: search for newly added files. ESP_LOGI(kTag, "scanning for new tracks"); - events::Ui().Dispatch(event::UpdateProgress{ - .stage = event::UpdateProgress::Stage::kScanningForNewTracks, - }); + uint64_t num_processed = 0; file_gatherer_.FindFiles("", [&](const std::pmr::string& path) { + num_processed++; + events::Ui().Dispatch(event::UpdateProgress{ + .stage = event::UpdateProgress::Stage::kScanningForNewTracks, + .val = num_processed, + }); + std::shared_ptr tags = tag_parser_.ReadAndParseTags(path); if (!tags || tags->encoding() == Container::kUnsupported) { // No parseable tags; skip this fiile. -- cgit v1.2.3