Skip to main content

Storage

Struct Storage 

Source
pub struct Storage { /* private fields */ }
Expand description

SQLite-backed storage for crawl data.

Uses WAL mode for concurrent-safe access and provides batch-friendly insert methods for performance. Includes an LRU cache for frequently accessed pages and memory usage tracking.

Implementations§

Source§

impl Storage

Source

pub fn conn(&self) -> MutexGuard<'_, Connection>

Lock and return the underlying connection guard.

Provides direct access to the SQLite connection for advanced queries or transactions not covered by the convenience methods.

Source

pub fn new(path: &Path) -> Result<Self, StorageError>

Open or create a SQLite database at the given path.

Enables WAL mode, memory-mapped I/O, and creates the schema if it doesn’t exist. Uses a default LRU cache of 1000 entries.

§Errors

Returns StorageError::Database if the database cannot be opened or the schema cannot be created.

Source

pub fn new_in_memory() -> Result<Self, StorageError>

Create in-memory storage for testing.

Uses an in-memory SQLite database with WAL mode enabled. Ideal for unit tests that need fast, isolated storage.

§Errors

Returns StorageError::Database if the in-memory database cannot be created.

Source

pub fn with_cache_size( path: &Path, cache_size: usize, ) -> Result<Self, StorageError>

Create storage with a custom LRU cache size.

Use this when the default 1000-entry cache is not appropriate for your workload. Larger caches improve read performance for repeat queries but use more memory.

§Errors

Returns StorageError::Database if the database cannot be opened.

Source

pub fn memory_usage(&self) -> usize

Returns the approximate memory usage in bytes.

Source

pub fn is_mmap_enabled(&self) -> bool

Returns whether memory-mapped I/O is enabled.

Source

pub fn cache_stats(&self) -> CacheStats

Returns cache statistics (hits, misses, current size).

Source

pub fn clear_cache(&self)

Clears the page cache.

Source

pub fn start_crawl( &self, target_url: &str, config_json: Option<&str>, ) -> Result<String, StorageError>

Start a new crawl and return its ID.

Source

pub fn finish_crawl( &self, crawl_id: &str, pages_crawled: usize, total_issues: usize, ) -> Result<(), StorageError>

Finish a crawl, recording final statistics.

Source

pub fn insert_page( &self, crawl_id: &str, page: &PageData, ) -> Result<(), StorageError>

Insert a single page into the database under the given crawl. Uses a single SQLite transaction for the page row + all link rows to avoid per-statement fsync overhead.

Source

pub fn insert_pages( &self, crawl_id: &str, pages: &[PageData], ) -> Result<(), StorageError>

Insert a batch of pages for performance. Wraps all inserts in a single SQLite transaction for O(n) vs O(n*fsync).

Source

pub fn insert_issue(&self, issue: &Issue) -> Result<(), StorageError>

Insert a single issue/finding into the database.

Source

pub fn insert_issues(&self, issues: &[Issue]) -> Result<(), StorageError>

Insert a batch of issues for performance.

Source

pub fn get_pages( &self, crawl_id: &str, limit: usize, ) -> Result<Vec<PageData>, StorageError>

Retrieve pages with a limit.

Results are not cached because the cache type (LruCache<String, PageData>) cannot store Vec<PageData>. The query is fast with proper indexing.

Source

pub fn get_issues( &self, crawl_id: &str, filters: &IssueFilter, ) -> Result<Vec<Issue>, StorageError>

Retrieve issues/finding with optional filters.

Source

pub fn get_pages_for_tenant( &self, crawl_id: &str, tenant_id: &str, limit: usize, ) -> Result<Vec<PageData>, StorageError>

Get pages for a specific tenant.

Returns pages belonging to the given tenant, or pages with no tenant assigned (shared/global data). This ensures tenant isolation at the storage layer while still allowing access to unscoped data.

Source

pub fn get_issues_for_tenant( &self, crawl_id: &str, tenant_id: &str, filters: &IssueFilter, ) -> Result<Vec<Issue>, StorageError>

Get issues for a specific tenant.

Returns issues belonging to the given tenant, or issues with no tenant assigned (shared/global data). This ensures tenant isolation at the storage layer while still allowing access to unscoped data.

Source

pub fn get_stats(&self, crawl_id: &str) -> Result<CrawlStats, StorageError>

Get aggregate statistics for a crawl.

Source

pub fn get_latest_crawl_id(&self) -> Result<Option<String>, StorageError>

Get the latest crawl ID.

Get all links for a crawl, grouped by source URL.

Returns Vec<(source_url, Vec<target_url>)> suitable for feeding into BacklinkAnalyzer::load_from_crawl_data.

Get all external links for a crawl.

Source

pub fn get_page_urls(&self, crawl_id: &str) -> Result<Vec<String>, StorageError>

Get all page URLs for a crawl.

Source

pub fn insert_crux_metrics( &self, page_id: &str, url: &str, lcp_p75: Option<f64>, inp_p75: Option<f64>, cls_p75: Option<f64>, fcp_p75: Option<f64>, ttfb_p75: Option<f64>, ) -> Result<(), StorageError>

Store CrUX metrics for a page.

Source

pub fn get_crux_metrics( &self, page_id: &str, ) -> Result<Option<CruxMetrics>, StorageError>

Get CrUX metrics for a page.

Source

pub fn get_crux_metrics_for_crawl( &self, crawl_id: &str, ) -> Result<Vec<CruxMetrics>, StorageError>

Get CrUX metrics for all pages in a crawl.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more