Decentralised Art Server
High-performance C++ backend that exposes HTML interface and a secure REST API for managing Performative Transactions entities
Loading...
Searching...
No Matches
sqlite_feed_store.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <filesystem>
5#include <memory>
6#include <optional>
7#include <string>
8#include <unordered_set>
9#include <vector>
10
11#include <sqlite3.h>
12
13#include "events_shard.hpp"
14#include "feed_store.hpp"
15
16namespace dcn::feed
17{
18 class SqliteFeedStore final : public IFeedStore
19 {
20 public:
22 const std::filesystem::path & feed_db_path,
23 const std::filesystem::path & archive_root,
24 std::int64_t outbox_retention_ms,
25 int default_chain_id,
26 std::string default_chain_namespace = "local");
27
28 ~SqliteFeedStore() override;
29
30 void applyChange(const events::ChangeRecord & row, std::int64_t now_ms) override;
31 void maintainOutbox(std::int64_t now_ms) override;
32 FeedPage getFeedPage(const FeedQuery & query) const override;
33 StreamPage getStreamPage(const StreamQuery & query) const override;
34 std::int64_t minAvailableStreamSeq() const override;
35 std::int64_t getFeedCursor() const override;
36 void setFeedCursor(std::int64_t last_change_seq) override;
37 bool runArchiveCycle(int chain_id, std::size_t hot_window_days, std::int64_t now_ms) override;
39
40 private:
41 bool _initializeFeedSchema();
42 bool _initializeArchiveSchema(sqlite3 * archive_db) const;
43 bool _exportMonth(const int chain_id, const std::string & month_token, const std::int64_t now_ms);
44 std::vector<std::filesystem::path> _candidateArchivePaths(const std::optional<CursorKey> & before_key) const;
45 void _appendFeedRowsFromDatabase(
46 sqlite3 * db,
47 const char * table_name,
48 const FeedQuery & query,
49 const std::optional<CursorKey> & before_key,
50 const std::size_t limit,
51 std::vector<FeedItem> & out_items,
52 std::unordered_set<std::string> & seen_feed_ids) const;
53
54 private:
55 std::filesystem::path _feed_db_path;
56 std::filesystem::path _archive_root;
57 std::int64_t _outbox_retention_ms = 0;
58
59 sqlite3 * _write_db = nullptr;
60 sqlite3 * _read_db = nullptr;
61 std::unique_ptr<events::IEventShardRouter> _shard_router;
62
63 int _default_chain_id = 1;
64 std::string _default_chain_namespace = "local";
65 };
66}
Definition feed_store.hpp:14
void setFeedCursor(std::int64_t last_change_seq) override
Definition sqlite_feed_store.cpp:1502
bool runArchiveCycle(int chain_id, std::size_t hot_window_days, std::int64_t now_ms) override
Definition sqlite_feed_store.cpp:404
StreamPage getStreamPage(const StreamQuery &query) const override
Definition sqlite_feed_store.cpp:637
std::int64_t minAvailableStreamSeq() const override
Definition sqlite_feed_store.cpp:742
void maintainOutbox(std::int64_t now_ms) override
Definition sqlite_feed_store.cpp:1520
storage::sqlite::WalCheckpointStats checkpointWal(storage::sqlite::WalCheckpointMode mode) override
Definition sqlite_feed_store.cpp:347
std::int64_t getFeedCursor() const override
Definition sqlite_feed_store.cpp:1482
FeedPage getFeedPage(const FeedQuery &query) const override
Definition sqlite_feed_store.cpp:535
~SqliteFeedStore() override
Definition sqlite_feed_store.cpp:329
void applyChange(const events::ChangeRecord &row, std::int64_t now_ms) override
Definition sqlite_feed_store.cpp:1606
SqliteFeedStore(const std::filesystem::path &feed_db_path, const std::filesystem::path &archive_root, std::int64_t outbox_retention_ms, int default_chain_id, std::string default_chain_namespace="local")
Definition sqlite_feed_store.cpp:228
Definition feed.hpp:17
WalCheckpointMode
Definition wal.hpp:9
Definition event_projector.hpp:38
Definition feed_types.hpp:57
Definition feed_types.hpp:49
Definition feed_types.hpp:81
Definition feed_types.hpp:64