diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-10-24 16:29:46 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-10-24 16:29:46 +1100 |
| commit | 2086ab09b8d89c27f524d82a68b9a2035ea02436 (patch) | |
| tree | e84765353237e23487b9fe6ceae8faeb13b2a94d /src/database/include | |
| parent | 4f8c127da926bc1e1724e7686a42d37c1da0f563 (diff) | |
| download | tangara-fw-2086ab09b8d89c27f524d82a68b9a2035ea02436.tar.gz | |
Implement incremental updates of database indexes
This makes rescanning the library *so* much faster. Yay!
Diffstat (limited to 'src/database/include')
| -rw-r--r-- | src/database/include/database.hpp | 6 | ||||
| -rw-r--r-- | src/database/include/index.hpp | 6 | ||||
| -rw-r--r-- | src/database/include/records.hpp | 3 | ||||
| -rw-r--r-- | src/database/include/track.hpp | 6 |
4 files changed, 20 insertions, 1 deletions
diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp index 7cb1d09c..cdf69db0 100644 --- a/src/database/include/database.hpp +++ b/src/database/include/database.hpp @@ -7,6 +7,7 @@ #pragma once #include <stdint.h> +#include <sys/_stdint.h> #include <cstdint> #include <future> #include <memory> @@ -150,6 +151,11 @@ class Database { auto dbPutHash(const uint64_t& hash, TrackId i) -> void; auto dbGetHash(const uint64_t& hash) -> std::optional<TrackId>; auto dbCreateIndexesForTrack(const Track& track) -> void; + auto dbRemoveIndexes(std::shared_ptr<TrackData>) -> void; + auto dbIngestTagHashes(const TrackTags&, + std::pmr::unordered_map<Tag, uint64_t>&) -> void; + auto dbRecoverTagsFromHashes(const std::pmr::unordered_map<Tag, uint64_t>&) + -> std::shared_ptr<TrackTags>; template <typename T> auto dbGetPage(const Continuation& c) -> Result<T>*; diff --git a/src/database/include/index.hpp b/src/database/include/index.hpp index 838eff31..13de952d 100644 --- a/src/database/include/index.hpp +++ b/src/database/include/index.hpp @@ -46,6 +46,8 @@ struct IndexKey { // an index consists of { kArtist, kAlbum, kTitle }, and we are at depth = 2 // then this may contain hash(hash("Jacqueline"), "My Cool Album"). std::uint64_t components_hash; + + bool operator==(const Header&) const = default; }; Header header; @@ -58,7 +60,9 @@ struct IndexKey { std::optional<TrackId> track; }; -auto Index(const IndexInfo&, const Track&, leveldb::WriteBatch*) -> bool; +auto Index(const IndexInfo&, const Track&) + -> std::vector<std::pair<IndexKey, std::pmr::string>>; + auto ExpandHeader(const IndexKey::Header&, const std::optional<std::pmr::string>&) -> IndexKey::Header; diff --git a/src/database/include/records.hpp b/src/database/include/records.hpp index e13c6568..09764ed0 100644 --- a/src/database/include/records.hpp +++ b/src/database/include/records.hpp @@ -52,6 +52,9 @@ auto EncodeHashKey(const uint64_t& hash) -> std::string; */ auto EncodeHashValue(TrackId id) -> std::string; +/* Encodes a hash key for the specified hash. */ +auto EncodeTagHashKey(const uint64_t& hash) -> std::string; + /* * Parses bytes previously encoded via EncodeHashValue back into a track id. May * return nullopt if parsing fails. diff --git a/src/database/include/track.hpp b/src/database/include/track.hpp index b07da9ba..72296e8d 100644 --- a/src/database/include/track.hpp +++ b/src/database/include/track.hpp @@ -83,6 +83,10 @@ class TrackTags { auto at(const Tag& key) const -> std::optional<std::pmr::string>; auto operator[](const Tag& key) const -> std::optional<std::pmr::string>; + auto tags() const -> const std::pmr::unordered_map<Tag, std::pmr::string>& { + return tags_; + } + /* * Returns a hash of the 'identifying' tags of this track. That is, a hash * that can be used to determine if one track is likely the same as another, @@ -119,12 +123,14 @@ struct TrackData { : id(0), filepath(&memory::kSpiRamResource), tags_hash(0), + individual_tag_hashes(&memory::kSpiRamResource), is_tombstoned(false), modified_at() {} TrackId id; std::pmr::string filepath; uint64_t tags_hash; + std::pmr::unordered_map<Tag, uint64_t> individual_tag_hashes; bool is_tombstoned; std::pair<uint16_t, uint16_t> modified_at; |
