summaryrefslogtreecommitdiff
path: root/src/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/database')
-rw-r--r--src/database/database.cpp20
-rw-r--r--src/database/file_gatherer.cpp12
-rw-r--r--src/database/include/db_events.hpp2
3 files changed, 26 insertions, 8 deletions
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<void> {
// 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<leveldb::Iterator> 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<TrackData> track = ParseDataValue(it->value());
if (!track) {
// The value was malformed. Drop this record.
@@ -195,10 +199,14 @@ auto Database::Update() -> std::future<void> {
// 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<TrackTags> tags = tag_parser_.ReadAndParseTags(path);
if (!tags || tags->encoding() == Container::kUnsupported) {
// No parseable tags; skip this fiile.
diff --git a/src/database/file_gatherer.cpp b/src/database/file_gatherer.cpp
index d8c80b0d..b4e87acb 100644
--- a/src/database/file_gatherer.cpp
+++ b/src/database/file_gatherer.cpp
@@ -14,6 +14,7 @@
#include "ff.h"
#include "memory_resource.hpp"
+#include "spi.hpp"
namespace database {
@@ -30,7 +31,11 @@ auto FileGathererImpl::FindFiles(
const TCHAR* next_path = static_cast<const TCHAR*>(next_path_str.c_str());
FF_DIR dir;
- FRESULT res = f_opendir(&dir, next_path);
+ FRESULT res;
+ {
+ auto lock = drivers::acquire_spi();
+ res = f_opendir(&dir, next_path);
+ }
if (res != FR_OK) {
// TODO: log.
continue;
@@ -38,7 +43,10 @@ auto FileGathererImpl::FindFiles(
for (;;) {
FILINFO info;
- res = f_readdir(&dir, &info);
+ {
+ auto lock = drivers::acquire_spi();
+ res = f_readdir(&dir, &info);
+ }
if (res != FR_OK || info.fname[0] == 0) {
// No more files in the directory.
break;
diff --git a/src/database/include/db_events.hpp b/src/database/include/db_events.hpp
index c071c6d4..a1aefc27 100644
--- a/src/database/include/db_events.hpp
+++ b/src/database/include/db_events.hpp
@@ -6,6 +6,7 @@
#pragma once
+#include <stdint.h>
#include "tinyfsm.hpp"
namespace database {
@@ -21,6 +22,7 @@ struct UpdateProgress : tinyfsm::Event {
kScanningForNewTracks,
};
Stage stage;
+ uint64_t val;
};
} // namespace event