From 245d9ff4b9cde1f487beed76085a52f3f2d6d26c Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 23 Jun 2023 15:32:11 +1000 Subject: add indexing to the database idk man i wrote most of this in a fugue state whilst high on the couch with my cat --- src/database/include/database.hpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/database/include/database.hpp') diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp index 8fecc5f6..77a17b75 100644 --- a/src/database/include/database.hpp +++ b/src/database/include/database.hpp @@ -16,6 +16,7 @@ #include #include "file_gatherer.hpp" +#include "index.hpp" #include "leveldb/cache.h" #include "leveldb/db.h" #include "leveldb/iterator.h" @@ -23,6 +24,7 @@ #include "leveldb/slice.h" #include "records.hpp" #include "result.hpp" +#include "shared_string.h" #include "tag_parser.hpp" #include "tasks.hpp" #include "track.hpp" @@ -66,6 +68,20 @@ class Result { std::optional> prev_page_; }; +class IndexRecord { + public: + explicit IndexRecord(const IndexKey&, std::optional); + + auto text() const -> std::optional; + auto track() const -> std::optional; + + auto Expand(std::size_t) const -> std::optional>; + + private: + IndexKey key_; + std::optional track_; +}; + class Database { public: enum DatabaseError { @@ -84,6 +100,9 @@ class Database { auto GetTrackPath(TrackId id) -> std::future>; + auto GetIndexes() -> std::vector; + auto GetTracksByIndex(const IndexInfo& index, std::size_t page_size) + -> std::future*>; auto GetTracks(std::size_t page_size) -> std::future*>; auto GetDump(std::size_t page_size) -> std::future*>; @@ -118,8 +137,7 @@ class Database { auto dbGetTrackData(TrackId id) -> std::optional; auto dbPutHash(const uint64_t& hash, TrackId i) -> void; auto dbGetHash(const uint64_t& hash) -> std::optional; - auto dbPutTrack(TrackId id, const std::string& path, const uint64_t& hash) - -> void; + auto dbCreateIndexesForTrack(Track track) -> void; template auto dbGetPage(const Continuation& c) -> Result*; @@ -129,6 +147,10 @@ class Database { -> std::optional; }; +template <> +auto Database::ParseRecord(const leveldb::Slice& key, + const leveldb::Slice& val) + -> std::optional; template <> auto Database::ParseRecord(const leveldb::Slice& key, const leveldb::Slice& val) -- cgit v1.2.3