summaryrefslogtreecommitdiff
path: root/src/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/database')
-rw-r--r--src/database/database.cpp26
-rw-r--r--src/database/include/database.hpp7
-rw-r--r--src/database/index.cpp9
3 files changed, 20 insertions, 22 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp
index 0d1c43e2..d0011abe 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -600,20 +600,12 @@ auto Database::ParseRecord<IndexRecord>(const leveldb::Slice& key,
return {};
}
- // If there was a track id included for this key, then this is a leaf record.
- // Fetch the actual track data instead of relying on the information in the
- // key.
- std::optional<Track> track;
- if (data->track) {
- std::optional<TrackData> track_data = dbGetTrackData(*data->track);
- TrackTags track_tags;
- if (track_data &&
- tag_parser_->ReadAndParseTags(track_data->filepath(), &track_tags)) {
- track.emplace(*track_data, track_tags);
- }
+ std::optional<std::string> title;
+ if (!val.empty()) {
+ title = val.ToString();
}
- return IndexRecord(*data, track);
+ return IndexRecord(*data, title, data->track);
}
template <>
@@ -663,17 +655,17 @@ auto Database::ParseRecord<std::string>(const leveldb::Slice& key,
return stream.str();
}
-IndexRecord::IndexRecord(const IndexKey& key, std::optional<Track> track)
- : key_(key), track_(track) {}
+IndexRecord::IndexRecord(const IndexKey& key, std::optional<shared_string> title, std::optional<TrackId> track)
+ : key_(key), override_text_(title), track_(track) {}
auto IndexRecord::text() const -> std::optional<shared_string> {
- if (track_) {
- return track_->TitleOrFilename();
+ if (override_text_) {
+ return override_text_;
}
return key_.item;
}
-auto IndexRecord::track() const -> std::optional<Track> {
+auto IndexRecord::track() const -> std::optional<TrackId> {
return track_;
}
diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp
index 7ffc15b0..f7e44299 100644
--- a/src/database/include/database.hpp
+++ b/src/database/include/database.hpp
@@ -70,16 +70,17 @@ class Result {
class IndexRecord {
public:
- explicit IndexRecord(const IndexKey&, std::optional<Track>);
+ explicit IndexRecord(const IndexKey&, std::optional<shared_string>, std::optional<TrackId>);
auto text() const -> std::optional<shared_string>;
- auto track() const -> std::optional<Track>;
+ auto track() const -> std::optional<TrackId>;
auto Expand(std::size_t) const -> std::optional<Continuation<IndexRecord>>;
private:
IndexKey key_;
- std::optional<Track> track_;
+ std::optional<shared_string> override_text_;
+ std::optional<TrackId> track_;
};
class Database {
diff --git a/src/database/index.cpp b/src/database/index.cpp
index a828578d..84d00bcd 100644
--- a/src/database/index.cpp
+++ b/src/database/index.cpp
@@ -52,15 +52,20 @@ auto Index(const IndexInfo& info, const Track& t, leveldb::WriteBatch* batch)
key.item = {};
}
- // If this is the last component, then we should also fill in the track id.
+ // If this is the last component, then we should also fill in the track id
+ // and title.
+ std::optional<std::string> title;
if (i == info.components.size() - 1) {
key.track = t.data().id();
+ if (info.components.at(i) != Tag::kTitle) {
+ title = t.TitleOrFilename();
+ }
} else {
key.track = {};
}
auto encoded = EncodeIndexKey(key);
- batch->Put(encoded.slice, leveldb::Slice{});
+ batch->Put(encoded.slice, title.value_or(""));
// If there are more components after this, then we need to finish by
// narrowing the header with the current title.