summaryrefslogtreecommitdiff
path: root/src/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/database')
-rw-r--r--src/database/database.cpp30
-rw-r--r--src/database/include/track.hpp3
-rw-r--r--src/database/track.cpp6
3 files changed, 37 insertions, 2 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp
index 6106693c..70bbb78a 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -35,6 +35,7 @@
#include "memory_resource.hpp"
#include "records.hpp"
#include "result.hpp"
+#include "spi.hpp"
#include "tag_parser.hpp"
#include "tasks.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.
ESP_LOGI(kTag, "verifying existing tracks");
{
@@ -205,6 +208,21 @@ auto Database::Update() -> std::future<void> {
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 =
tag_parser_.ReadAndParseTags(track->filepath());
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
// this record.
ESP_LOGW(kTag, "entombing missing #%lx", track->id());
- dbPutTrackData(track->Entomb());
+ dbPutTrackData(track->Entomb().UpdateModifiedAt(modified_at));
it->Next();
continue;
}
@@ -227,7 +245,8 @@ auto Database::Update() -> std::future<void> {
// database.
ESP_LOGI(kTag, "updating hash (%llx -> %llx)", track->tags_hash(),
new_hash);
- dbPutTrackData(track->UpdateHash(new_hash));
+ dbPutTrackData(
+ track->UpdateHash(new_hash).UpdateModifiedAt(modified_at));
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.
ESP_LOGI(kTag, "scanning for new tracks");
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};
+ if (modified < newest_track) {
+ ESP_LOGI(kTag, "skipping old file");
+ return;
+ }
std::shared_ptr<TrackTags> tags = tag_parser_.ReadAndParseTags(path);
if (!tags || tags->encoding() == Container::kUnsupported) {
diff --git a/src/database/include/track.hpp b/src/database/include/track.hpp
index 1067b25e..af5f53df 100644
--- a/src/database/include/track.hpp
+++ b/src/database/include/track.hpp
@@ -170,6 +170,9 @@ class TrackData {
* new location.
*/
auto Exhume(const std::pmr::string& new_path) const -> TrackData;
+
+ auto UpdateModifiedAt(const std::pair<uint16_t, uint16_t>&) const
+ -> TrackData;
};
/*
diff --git a/src/database/track.cpp b/src/database/track.cpp
index 551379c6..6fc891a4 100644
--- a/src/database/track.cpp
+++ b/src/database/track.cpp
@@ -7,6 +7,7 @@
#include "track.hpp"
#include <komihash.h>
+#include <sys/_stdint.h>
#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_);
}
+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 title = tags().at(Tag::kTitle);
if (title) {