diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-02-29 12:10:44 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-02-29 12:10:44 +1100 |
| commit | 7d3ddac0eaea207aee187729e3beec95d8d201dc (patch) | |
| tree | 4b4545e725697663a4768630c48f49e8bbb8cf59 /src/database | |
| parent | d41f9f703375171d5766840c9edec32ff47bb25d (diff) | |
| parent | 9fca08f8434a05e1fe93a1c4f8133f0e7fc118bf (diff) | |
| download | tangara-fw-7d3ddac0eaea207aee187729e3beec95d8d201dc.tar.gz | |
Merge branch 'main' into seek-support
Diffstat (limited to 'src/database')
| -rw-r--r-- | src/database/database.cpp | 7 | ||||
| -rw-r--r-- | src/database/file_gatherer.cpp | 10 | ||||
| -rw-r--r-- | src/database/include/file_gatherer.hpp | 4 | ||||
| -rw-r--r-- | src/database/include/tag_parser.hpp | 6 | ||||
| -rw-r--r-- | 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<uint16_t, uint16_t> 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<void(const std::string&, const FILINFO&)> cb) -> void { - std::deque<std::string> to_explore; - to_explore.push_back(root); + std::function<void(std::string_view, const FILINFO&)> cb) -> void { + std::pmr::deque<std::pmr::string> 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<const TCHAR*>(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<void(const std::string&, const FILINFO&)> cb) + std::function<void(std::string_view, const FILINFO&)> cb) -> void = 0; }; @@ -29,7 +29,7 @@ class FileGathererImpl : public IFileGatherer { public: virtual auto FindFiles( const std::string& root, - std::function<void(const std::string&, const FILINFO&)> cb) + std::function<void(std::string_view, const FILINFO&)> 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<TrackTags> = 0; }; class TagParserImpl : public ITagParser { public: TagParserImpl(); - auto ReadAndParseTags(const std::string& path) + auto ReadAndParseTags(std::string_view path) -> std::shared_ptr<TrackTags> override; private: - auto parseNew(const std::string& path) -> std::shared_ptr<TrackTags>; + auto parseNew(std::string_view path) -> std::shared_ptr<TrackTags>; /* * 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<TrackTags> { { std::lock_guard<std::mutex> 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<TrackTags> { +auto TagParserImpl::parseNew(std::string_view p) -> std::shared_ptr<TrackTags> { + std::string path{p}; libtags::Aux aux; auto out = TrackTags::create(); aux.tags = out.get(); |
