oxgraph_postgres/config.rs
1//! Operational configuration mirrored from extension GUCs.
2
3use crate::error::{ConfigError, PostgresGraphError};
4
5/// Freshness policy when overlays and sync rows are present.
6#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
7pub enum QueryFreshness {
8 /// Read the frozen base artifact only (skip overlay edge inserts) while still
9 /// honoring node tombstones recorded in the overlay.
10 BaseOnly,
11 /// Apply overlays and sync replay before each query.
12 #[default]
13 OverlayAware,
14}
15
16/// Library-side operational configuration (GUC values are registered in `oxgraph-pgrx`).
17#[derive(Clone, Debug, PartialEq, Eq)]
18pub struct Config {
19 /// Maximum BFS expansion steps per traverse call.
20 pub traverse_limit: u32,
21 /// Maximum rows returned from search.
22 pub search_limit: u32,
23 /// Overlay/sync freshness policy.
24 pub query_freshness: QueryFreshness,
25 /// Whether maintenance rebuilds are permitted.
26 pub maintenance_enabled: bool,
27}
28
29impl Default for Config {
30 fn default() -> Self {
31 Self {
32 traverse_limit: 10_000,
33 search_limit: 10_000,
34 query_freshness: QueryFreshness::OverlayAware,
35 maintenance_enabled: true,
36 }
37 }
38}
39
40impl Config {
41 /// Validates limits and returns an error for zero limits.
42 ///
43 /// # Errors
44 ///
45 /// Returns [`PostgresGraphError::Config`] when a limit is zero.
46 ///
47 /// # Performance
48 ///
49 /// This method is `O(1)`.
50 pub fn validate(&self) -> Result<(), PostgresGraphError> {
51 if self.traverse_limit == 0 {
52 return Err(ConfigError::ZeroTraverseLimit.into());
53 }
54 if self.search_limit == 0 {
55 return Err(ConfigError::ZeroSearchLimit.into());
56 }
57 Ok(())
58 }
59}