async fn warm_index(&self) -> anyhow::Result<()> {
        // Read all invoices
        debug!("Beginning index warm from {}", self.root.display());
        let mut total_indexed: u64 = 0;
        // Check if the invoice directory exists. If it doesn't, this is likely the first time and
        // we should just return
        let invoice_path = self.invoice_path("");
        match tokio::fs::metadata(&invoice_path).await {
            Ok(_) => (),
            Err(e) if matches!(e.kind(), std::io::ErrorKind::NotFound) => return Ok(()),
            Err(e) => return Err(e.into()),
        };
        let mut readdir = tokio::fs::read_dir(invoice_path).await?;
        while let Some(e) = readdir.next().await {
            let p = match e {
                Ok(path) => path.path(),
                Err(e) => {
                    error!("Error while reading directory entry: {:?}", e);
                    continue;
                }
            };
            let sha = match p.file_name().map(|f| f.to_string_lossy()) {
                Some(sha_opt) => sha_opt,
                None => continue,
            };
            log::info!("Loading invoice {}/invoice.toml into search index", sha);
            // Load invoice
            let inv_path = self.invoice_toml_path(&sha);
            // Open file
            let inv_toml = std::fs::read_to_string(inv_path)?;

            // Parse
            let invoice: crate::Invoice = toml::from_str(inv_toml.as_str())?;
            let digest = invoice.canonical_name();
            if sha != digest {
                return Err(anyhow::anyhow!(
                    "SHA {} did not match computed digest {}. Delete this record.",
                    sha,
                    digest
                ));
            }

            if let Err(e) = self.index.index(&invoice).await {
                log::error!("Error indexing {}: {}", sha, e);
            }
            total_indexed += 1;
        }
        trace!("Warmed index with {} entries", total_indexed);
        Ok(())
    }
/// This warms the index by loading all of the invoices currently on disk.
///
/// Warming the index is something that the storage backend should do, though I am
/// not sure whether EVERY storage backend should do it. It is the responsibility of
/// storage because storage is the sole authority about what documents are actually
/// in the repository. So it needs to communicate (on startup) what documents it knows
/// about. The storage engine merely needs to store any non-duplicates. So we can
/// safely insert, but ignore errors that come back because of duplicate entries.
This warms the index by loading all of the invoices currently on disk.
Warming the index is something that the storage backend should do, though I am
not sure whether EVERY storage backend should do it. It is the responsibility of
storage because storage is the sole authority about what documents are actually
in the repository. So it needs to communicate (on startup) what documents it knows
about. The storage engine merely needs to store any non-duplicates. So we can
safely insert, but ignore errors that come back because of duplicate entries.
This warms the index by loading all of the invoices currently on disk . Warming the index is something that the storage backend should do though I am not sure whether EVERY storage backend should do it . It is the responsibility of storage because storage is the sole authority about what documents are actually in the repository . So it needs to communicate ( on startup ) what documents it knows about . The storage engine merely needs to store any non - duplicates . So we can safely insert but ignore errors that come back because of duplicate entries .
async fn warm_index(&self) -> anyhow::Result<()> {
        // Read all invoices
        debug!("Beginning index warm from {}", self.root.display());
        let mut total_indexed: u64 = 0;
        // Check if the invoice directory exists. If it doesn't, this is likely the first time and
        // we should just return
        let invoice_path = self.invoice_path("");
        match tokio::fs::metadata(&invoice_path).await {
            Ok(_) => (),
            Err(e) if matches!(e.kind(), std::io::ErrorKind::NotFound) => return Ok(()),
            Err(e) => return Err(e.into()),
        };
        let mut readdir = tokio::fs::read_dir(invoice_path).await?;
        while let Some(e) = readdir.next().await {
            let p = match e {
                Ok(path) => path.path(),
                Err(e) => {
                    error!("Error while reading directory entry: {:?}", e);
                    continue;
                }
            };
            let sha = match p.file_name().map(|f| f.to_string_lossy()) {
                Some(sha_opt) => sha_opt,
                None => continue,
            };
            log::info!("Loading invoice {}/invoice.toml into search index", sha);
            // Load invoice
            let inv_path = self.invoice_toml_path(&sha);
            // Open file
            let inv_toml = std::fs::read_to_string(inv_path)?;
            // Parse
            let invoice: crate::Invoice = toml::from_str(inv_toml.as_str())?;
            let digest = invoice.canonical_name();
            if sha != digest {
                return Err(anyhow::anyhow!(
                    "SHA {} did not match computed digest {}. Delete this record.",
                    sha,
                    digest
                ));
            }
            if let Err(e) = self.index.index(&invoice).await {
                log::error!("Error indexing {}: {}", sha, e);
            }
            total_indexed += 1;
        }
        trace!("Warmed index with {} entries", total_indexed);
        Ok(())
    }
async fn warm_index ( & self ) -> anyhow :: Result < ( ) > { // Read all invoices debug ! ( " " self root display ( ) ) ; let mut total_indexed : u64 = 0 ; // Check if the invoice directory exists. If it doesn't, this is likely the first time and // we should just return let invoice_path = self . invoice_path ( " " ) ; match tokio :: fs :: metadata ( & invoice_path ) . await { Ok ( _ ) => ( ) , Err ( e ) if matches ! ( e kind ( ) std io ErrorKind NotFound ) => return Ok ( ( ) ) , Err ( e ) => return Err ( e . into ( ) ) , } ; let mut readdir = tokio :: fs :: read_dir ( invoice_path ) . await ? ; while let Some ( e ) = readdir . next ( ) . await { let p = match e { Ok ( path ) => path . path ( ) , Err ( e ) => { error ! ( " " e ) ; continue ; } } ; let sha = match p . file_name ( ) . map ( | f | f . to_string_lossy ( ) ) { Some ( sha_opt ) => sha_opt , None => continue , } ; log :: info ! ( " " sha ) ; // Load invoice let inv_path = self . invoice_toml_path ( & sha ) ; // Open file let inv_toml = std :: fs :: read_to_string ( inv_path ) ? ; // Parse let invoice : crate :: Invoice = toml :: from_str ( inv_toml . as_str ( ) ) ? ; let digest = invoice . canonical_name ( ) ; if sha != digest { return Err ( anyhow :: anyhow ! ( " " sha digest ) ) ; } if let Err ( e ) = self . index . index ( & invoice ) . await { log :: error ! ( " " sha e ) ; } total_indexed += 1 ; } trace ! ( " " total_indexed ) ; Ok ( ( ) ) }
This warms the index by loading all of the invoices currently on disk.
This warms the index by loading all of the invoices currently on disk .
&self
&self