From 5866513c532114654c1a0e616be3c64ef0aa92ed Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 16 Feb 2024 15:13:58 +1100 Subject: [PATCH] Move the list of unexplored files into spiram --- src/database/database.cpp | 7 ++----- src/database/file_gatherer.cpp | 10 +++++----- src/database/include/file_gatherer.hpp | 4 ++-- src/database/include/tag_parser.hpp | 6 +++--- src/database/tag_parser.cpp | 8 ++++---- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/database/database.cpp b/src/database/database.cpp index b596063c..ec11455b 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -383,8 +383,7 @@ auto Database::updateIndexes() -> void { ESP_LOGI(kTag, "scanning for new tracks"); uint64_t num_processed = 0; std::pair newest_track = last_update; - file_gatherer_.FindFiles("", [&](const std::string& path, - const FILINFO& info) { + file_gatherer_.FindFiles("", [&](std::string_view path, const FILINFO& info) { num_processed++; events::Ui().Dispatch(event::UpdateProgress{ .stage = event::UpdateProgress::Stage::kScanningForNewTracks, @@ -456,9 +455,7 @@ auto Database::updateIndexes() -> void { dbCreateIndexesForTrack(*t); } else if (existing_data->filepath != std::pmr::string{path.data(), path.size()}) { - ESP_LOGW(kTag, "tag hash collision for %s and %s", - existing_data->filepath.c_str(), path.c_str()); - ESP_LOGI(kTag, "hash components: %s, %s, %s", + ESP_LOGW(kTag, "hash collision: %s, %s, %s", tags->title().value_or("no title").c_str(), tags->artist().value_or("no artist").c_str(), tags->album().value_or("no album").c_str()); diff --git a/src/database/file_gatherer.cpp b/src/database/file_gatherer.cpp index dde363bd..b7b7271e 100644 --- a/src/database/file_gatherer.cpp +++ b/src/database/file_gatherer.cpp @@ -22,12 +22,12 @@ static_assert(sizeof(TCHAR) == sizeof(char), "TCHAR must be CHAR"); auto FileGathererImpl::FindFiles( const std::string& root, - std::function cb) -> void { - std::deque to_explore; - to_explore.push_back(root); + std::function cb) -> void { + std::pmr::deque to_explore{&memory::kSpiRamResource}; + to_explore.push_back({root.data(), root.size()}); while (!to_explore.empty()) { - std::string next_path_str = to_explore.front(); + auto next_path_str = to_explore.front(); to_explore.pop_front(); const TCHAR* next_path = static_cast(next_path_str.c_str()); @@ -56,7 +56,7 @@ auto FileGathererImpl::FindFiles( // System or hidden file. Ignore it and move on. continue; } else { - std::string full_path; + std::pmr::string full_path{&memory::kSpiRamResource}; full_path += next_path_str; full_path += "/"; full_path += info.fname; diff --git a/src/database/include/file_gatherer.hpp b/src/database/include/file_gatherer.hpp index 66127bb7..685bdb2c 100644 --- a/src/database/include/file_gatherer.hpp +++ b/src/database/include/file_gatherer.hpp @@ -21,7 +21,7 @@ class IFileGatherer { virtual auto FindFiles( const std::string& root, - std::function cb) + std::function cb) -> void = 0; }; @@ -29,7 +29,7 @@ class FileGathererImpl : public IFileGatherer { public: virtual auto FindFiles( const std::string& root, - std::function cb) + std::function cb) -> void override; }; diff --git a/src/database/include/tag_parser.hpp b/src/database/include/tag_parser.hpp index f196c479..966258b5 100644 --- a/src/database/include/tag_parser.hpp +++ b/src/database/include/tag_parser.hpp @@ -16,18 +16,18 @@ namespace database { class ITagParser { public: virtual ~ITagParser() {} - virtual auto ReadAndParseTags(const std::string& path) + virtual auto ReadAndParseTags(std::string_view path) -> std::shared_ptr = 0; }; class TagParserImpl : public ITagParser { public: TagParserImpl(); - auto ReadAndParseTags(const std::string& path) + auto ReadAndParseTags(std::string_view path) -> std::shared_ptr override; private: - auto parseNew(const std::string& path) -> std::shared_ptr; + auto parseNew(std::string_view path) -> std::shared_ptr; /* * Cache of tags that have already been extracted from files. Ideally this diff --git a/src/database/tag_parser.cpp b/src/database/tag_parser.cpp index c247bb7d..cbcbdcb5 100644 --- a/src/database/tag_parser.cpp +++ b/src/database/tag_parser.cpp @@ -108,7 +108,7 @@ static const std::size_t kBufSize = 1024; TagParserImpl::TagParserImpl() {} -auto TagParserImpl::ReadAndParseTags(const std::string& path) +auto TagParserImpl::ReadAndParseTags(std::string_view path) -> std::shared_ptr { { std::lock_guard lock{cache_mutex_}; @@ -130,7 +130,7 @@ auto TagParserImpl::ReadAndParseTags(const std::string& path) if (!tags->track()) { auto slash_pos = path.find_last_of("/"); if (slash_pos != std::string::npos && path.size() - slash_pos > 1) { - std::string trunc = path.substr(slash_pos + 1); + auto trunc = path.substr(slash_pos + 1); tags->track({trunc.data(), trunc.size()}); } } @@ -143,8 +143,8 @@ auto TagParserImpl::ReadAndParseTags(const std::string& path) return tags; } -auto TagParserImpl::parseNew(const std::string& path) - -> std::shared_ptr { +auto TagParserImpl::parseNew(std::string_view p) -> std::shared_ptr { + std::string path{p}; libtags::Aux aux; auto out = TrackTags::create(); aux.tags = out.get();