Skip old tracks when scanning the sd card

custom
jacqueline 2 years ago
parent ddf0128496
commit 5b5b792467
  1. 30
      src/database/database.cpp
  2. 3
      src/database/include/track.hpp
  3. 6
      src/database/track.cpp

@ -35,6 +35,7 @@
#include "memory_resource.hpp" #include "memory_resource.hpp"
#include "records.hpp" #include "records.hpp"
#include "result.hpp" #include "result.hpp"
#include "spi.hpp"
#include "tag_parser.hpp" #include "tag_parser.hpp"
#include "tasks.hpp" #include "tasks.hpp"
#include "track.hpp" #include "track.hpp"
@ -176,6 +177,8 @@ auto Database::Update() -> std::future<void> {
} }
} }
std::pair<uint16_t, uint16_t> newest_track{0, 0};
// Stage 1: verify all existing tracks are still valid. // Stage 1: verify all existing tracks are still valid.
ESP_LOGI(kTag, "verifying existing tracks"); ESP_LOGI(kTag, "verifying existing tracks");
{ {
@ -205,6 +208,21 @@ auto Database::Update() -> std::future<void> {
continue; continue;
} }
FRESULT res;
FILINFO info;
{
auto lock = drivers::acquire_spi();
res = f_stat(track->filepath().c_str(), &info);
}
std::pair<uint16_t, uint16_t> modified_at{0, 0};
if (res == FR_OK) {
modified_at = {info.fdate, info.ftime};
}
if (modified_at == track->modified_at()) {
newest_track = std::max(modified_at, newest_track);
}
std::shared_ptr<TrackTags> tags = std::shared_ptr<TrackTags> tags =
tag_parser_.ReadAndParseTags(track->filepath()); tag_parser_.ReadAndParseTags(track->filepath());
if (!tags || tags->encoding() == Container::kUnsupported) { if (!tags || tags->encoding() == Container::kUnsupported) {
@ -212,7 +230,7 @@ auto Database::Update() -> std::future<void> {
// malformed, or perhaps the file is missing. Either way, tombstone // malformed, or perhaps the file is missing. Either way, tombstone
// this record. // this record.
ESP_LOGW(kTag, "entombing missing #%lx", track->id()); ESP_LOGW(kTag, "entombing missing #%lx", track->id());
dbPutTrackData(track->Entomb()); dbPutTrackData(track->Entomb().UpdateModifiedAt(modified_at));
it->Next(); it->Next();
continue; continue;
} }
@ -227,7 +245,8 @@ auto Database::Update() -> std::future<void> {
// database. // database.
ESP_LOGI(kTag, "updating hash (%llx -> %llx)", track->tags_hash(), ESP_LOGI(kTag, "updating hash (%llx -> %llx)", track->tags_hash(),
new_hash); new_hash);
dbPutTrackData(track->UpdateHash(new_hash)); dbPutTrackData(
track->UpdateHash(new_hash).UpdateModifiedAt(modified_at));
dbPutHash(new_hash, track->id()); dbPutHash(new_hash, track->id());
} }
@ -239,6 +258,9 @@ auto Database::Update() -> std::future<void> {
} }
} }
ESP_LOGI(kTag, "newest unmodified was at %u,%u", newest_track.first,
newest_track.second);
// Stage 2: search for newly added files. // Stage 2: search for newly added files.
ESP_LOGI(kTag, "scanning for new tracks"); ESP_LOGI(kTag, "scanning for new tracks");
uint64_t num_processed = 0; uint64_t num_processed = 0;
@ -251,6 +273,10 @@ auto Database::Update() -> std::future<void> {
}); });
std::pair<uint16_t, uint16_t> modified{info.fdate, info.ftime}; std::pair<uint16_t, uint16_t> modified{info.fdate, info.ftime};
if (modified < newest_track) {
ESP_LOGI(kTag, "skipping old file");
return;
}
std::shared_ptr<TrackTags> tags = tag_parser_.ReadAndParseTags(path); std::shared_ptr<TrackTags> tags = tag_parser_.ReadAndParseTags(path);
if (!tags || tags->encoding() == Container::kUnsupported) { if (!tags || tags->encoding() == Container::kUnsupported) {

@ -170,6 +170,9 @@ class TrackData {
* new location. * new location.
*/ */
auto Exhume(const std::pmr::string& new_path) const -> TrackData; auto Exhume(const std::pmr::string& new_path) const -> TrackData;
auto UpdateModifiedAt(const std::pair<uint16_t, uint16_t>&) const
-> TrackData;
}; };
/* /*

@ -7,6 +7,7 @@
#include "track.hpp" #include "track.hpp"
#include <komihash.h> #include <komihash.h>
#include <sys/_stdint.h>
#include "memory_resource.hpp" #include "memory_resource.hpp"
@ -64,6 +65,11 @@ auto TrackData::Exhume(const std::pmr::string& new_path) const -> TrackData {
return TrackData(id_, new_path, tags_hash_, false, modified_at_); return TrackData(id_, new_path, tags_hash_, false, modified_at_);
} }
auto TrackData::UpdateModifiedAt(
const std::pair<uint16_t, uint16_t>& new_time) const -> TrackData {
return TrackData(id_, filepath_, tags_hash_, false, new_time);
}
auto Track::TitleOrFilename() const -> std::pmr::string { auto Track::TitleOrFilename() const -> std::pmr::string {
auto title = tags().at(Tag::kTitle); auto title = tags().at(Tag::kTitle);
if (title) { if (title) {

Loading…
Cancel
Save