1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! Bounded, read-only traversal of the authored-time social-post index.
use rostra_core::event::content_kind::SocialPost;
use rostra_core::id::RostraId;
use rostra_core::{ShortEventId, Timestamp};
use crate::social::EventPaginationCursor;
/// Independent limits and early filters for one read snapshot.
#[derive(Clone, Copy, Debug)]
pub struct SocialPostScanRequest {
/// Inclusive upper key; use the previous page's continuation unchanged.
pub cursor: Option<EventPaginationCursor>,
/// Inclusive lower authored timestamp, or the beginning of time.
pub authored_from: Option<Timestamp>,
/// Inclusive upper authored timestamp, or the end of time.
pub authored_through: Option<Timestamp>,
/// Optional exact author filter, applied before content decoding.
pub author: Option<RostraId>,
/// Maximum index rows examined, including hidden and filtered rows.
pub max_rows: usize,
/// Maximum cumulative raw CBOR bytes submitted to content deserialization.
pub max_content_bytes: usize,
/// Maximum returned records; one supports caller-side output budgeting.
pub max_records: usize,
}
/// A surviving locally retained post, without unbounded reply-count metadata.
#[derive(Clone, Debug)]
pub struct SocialPostScanRow {
/// Author-provided timestamp used by the index.
pub ts: Timestamp,
/// Full author identity.
pub author: RostraId,
/// Event identity in the local social-post index.
pub event_id: ShortEventId,
/// Complete decoded content, never truncated for matching.
pub content: SocialPost,
}
/// Why a bounded scan stopped.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SocialPostScanStop {
/// No remaining index keys in the requested range in this snapshot.
Exhausted,
/// The index-row allowance was reached, without probing another row.
RowBudget,
/// The output-count allowance was reached, without probing another row.
RecordBudget,
/// The next eligible payload exceeds the remaining byte allowance.
ContentByteBudget,
/// One eligible payload exceeds the entire byte allowance.
ContentTooLarge,
}
/// Results, honest work counters, and continuation from one read snapshot.
#[derive(Clone, Debug)]
pub struct SocialPostScanPage {
/// Eligible records in descending `(authored timestamp, event ID)` order.
pub rows: Vec<SocialPostScanRow>,
/// Inclusive upper boundary of the unprocessed range, possibly absent as a
/// stored key. A budget stop can require an empty final call to prove
/// exhaustion. An indivisible oversized record remains at its exact key.
pub next_cursor: Option<EventPaginationCursor>,
/// Exhaustion or the specific limiting resource.
pub stop: SocialPostScanStop,
/// Actual index rows examined, including a byte-blocked candidate.
pub rows_scanned: usize,
/// Raw CBOR bytes submitted to the decoder, including invalid content.
pub content_bytes_decoded: usize,
/// Content deserialization attempts, including invalid content.
pub contents_decoded: usize,
}
/// Compute an inclusive boundary without reading an uncharged lookahead row.
pub(crate) fn predecessor(cursor: EventPaginationCursor) -> Option<EventPaginationCursor> {
let id = u128::from_be_bytes(cursor.event_id.to_bytes());
if let Some(id) = id.checked_sub(1) {
Some(EventPaginationCursor {
ts: cursor.ts,
event_id: ShortEventId::from_bytes(id.to_be_bytes()),
})
} else {
cursor
.ts
.as_u64()
.checked_sub(1)
.map(|ts| EventPaginationCursor {
ts: ts.into(),
event_id: ShortEventId::MAX,
})
}
}