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
//! Operational configuration mirrored from extension GUCs.
use crate::error::{ConfigError, PostgresGraphError};
/// Freshness policy when overlays and sync rows are present.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum QueryFreshness {
/// Read the frozen base artifact only (skip overlay edge inserts) while still
/// honoring node tombstones recorded in the overlay.
BaseOnly,
/// Apply overlays and sync replay before each query.
#[default]
OverlayAware,
}
/// Library-side operational configuration (GUC values are registered in `oxgraph-pgrx`).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Config {
/// Maximum BFS expansion steps per traverse call.
pub traverse_limit: u32,
/// Maximum rows returned from search.
pub search_limit: u32,
/// Overlay/sync freshness policy.
pub query_freshness: QueryFreshness,
/// Whether maintenance rebuilds are permitted.
pub maintenance_enabled: bool,
}
impl Default for Config {
fn default() -> Self {
Self {
traverse_limit: 10_000,
search_limit: 10_000,
query_freshness: QueryFreshness::OverlayAware,
maintenance_enabled: true,
}
}
}
impl Config {
/// Validates limits and returns an error for zero limits.
///
/// # Errors
///
/// Returns [`PostgresGraphError::Config`] when a limit is zero.
///
/// # Performance
///
/// This method is `O(1)`.
pub fn validate(&self) -> Result<(), PostgresGraphError> {
if self.traverse_limit == 0 {
return Err(ConfigError::ZeroTraverseLimit.into());
}
if self.search_limit == 0 {
return Err(ConfigError::ZeroSearchLimit.into());
}
Ok(())
}
}