MCPcopy Create free account
hub / github.com/AppFlowy-IO/AppFlowy-Collab / init_database_rows

Method init_database_rows

collab/src/database/database.rs:579–621  ·  view source on GitHub ↗
(
    &'a self,
    row_ids: Vec<T>,
    chunk_size: usize,
    cancel_token: Option<CancellationToken>,
    auto_fetch: bool,
  )

Source from the content-addressed store, hash-verified

577 }
578
579 pub fn init_database_rows<'a, T: Into<RowId> + Send + 'a>(
580 &'a self,
581 row_ids: Vec<T>,
582 chunk_size: usize,
583 cancel_token: Option<CancellationToken>,
584 auto_fetch: bool,
585 ) -> BoxStream<'a, Result<Arc<RwLock<DatabaseRow>>, CollabError>> {
586 let row_ids_chunk_stream = stream::iter(
587 row_ids
588 .into_iter()
589 .map(Into::into)
590 .collect::<Vec<RowId>>()
591 .chunks(chunk_size)
592 .map(|chunk| chunk.to_vec())
593 .collect::<Vec<Vec<RowId>>>(),
594 );
595
596 // Stream that processes each chunk and yields rows, checking for cancellation if the token is provided
597 row_ids_chunk_stream
598 .then(move |chunk| {
599 let cancel_token = cancel_token.clone();
600 async move {
601 if let Some(ref token) = cancel_token {
602 if token.is_cancelled() {
603 return Err(CollabError::DatabaseActionCancelled);
604 }
605 }
606
607 self.body.block.init_database_rows(chunk, auto_fetch).await
608 }
609 })
610 .filter_map(|result| async {
611 match result {
612 Ok(rows) => Some(stream::iter(rows.into_iter().map(Ok))),
613 Err(err) => {
614 error!("Error initializing database rows: {:?}", err);
615 None
616 },
617 }
618 })
619 .flatten()
620 .boxed()
621 }
622
623 /// Return the cached [DatabaseRow] if it is already initialized.
624 pub fn get_cached_database_row(&self, row_id: &RowId) -> Option<Arc<RwLock<DatabaseRow>>> {

Callers 1

Calls 2

into_iterMethod · 0.80
to_vecMethod · 0.80

Tested by

no test coverage detected