Skip to content

Commit 4ec72da

Browse files
authored
chore: use uuid (#415)
* chore: use uuid * chore: fmt * chore: fmt * chore: fix test * chore: remove create database id * chore: make folder current view as option * chore: uuid on viewmap * chore: uuid on viewupdate * chore: uuid for collab resource * chore: uuid for IdMapper, FolderCollabRemapper, WorkspaceRemapper * chore: uuid for IdMapper,WorkspaceDatabaseMeta,CollabMetadata * chore: fmt * chore: uuid idmapper * chore: uuid importer * chore: uuid importer * chore: uuid ViewsMap * chore: fmt * chore: clippy * chore:revert uuid for parent_view_id * chore: fix test * chore: box stream * chore: return uuid
1 parent 436c733 commit 4ec72da

File tree

115 files changed

+3378
-2094
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+3378
-2094
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ collab-plugins/.env.test
1818
**/temp/**
1919

2020
**/.DS_Store
21-
.claude
21+
.claude
22+

collab-database/src/blocks/block.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::error::DatabaseError;
22
use crate::rows::{
3-
Cell, CreateRowParams, DatabaseRow, Row, RowChangeSender, RowDetail, RowId, RowMeta, RowMetaKey,
3+
Cell, CreateRowParams, DatabaseRow, Row, RowChangeSender, RowDetail, RowMeta, RowMetaKey,
44
RowMetaUpdate, RowUpdate, meta_id_from_row_id,
55
};
66
use crate::views::RowOrder;
7+
use collab_entity::uuid_validation::{DatabaseId, RowId};
78

89
use collab::lock::RwLock;
910
use std::sync::Arc;
@@ -12,7 +13,6 @@ use tokio::sync::broadcast::Sender;
1213

1314
use crate::database_trait::{DatabaseRowCollabService, DatabaseRowDataVariant};
1415
use tracing::{instrument, trace};
15-
use uuid::Uuid;
1616
use yrs::block::ClientID;
1717

1818
#[derive(Clone, Debug)]
@@ -29,15 +29,15 @@ pub type InitRowChan =
2929
/// might want to split the rows into multiple [Block]s to improve performance.
3030
#[derive(Clone)]
3131
pub struct Block {
32-
database_id: String,
32+
database_id: DatabaseId,
3333
collab_service: Arc<dyn DatabaseRowCollabService>,
3434
pub notifier: Arc<Sender<BlockEvent>>,
3535
row_change_tx: Option<RowChangeSender>,
3636
}
3737

3838
impl Block {
3939
pub fn new(
40-
database_id: String,
40+
database_id: DatabaseId,
4141
collab_service: Arc<dyn DatabaseRowCollabService>,
4242
row_change_tx: Option<RowChangeSender>,
4343
) -> Block {
@@ -96,9 +96,9 @@ impl Block {
9696
) -> Result<RowOrder, DatabaseError> {
9797
let params = row_params.into();
9898
let row: Row = params.clone().into();
99-
let row_id = row.id.clone();
99+
let row_id = row.id;
100100
let row_order = RowOrder {
101-
id: row.id.clone(),
101+
id: row.id,
102102
height: row.height,
103103
};
104104

@@ -144,8 +144,7 @@ impl Block {
144144
}
145145

146146
pub fn get_row_document_id(&self, row_id: &RowId) -> Option<String> {
147-
let row_id = Uuid::parse_str(row_id).ok()?;
148-
Some(meta_id_from_row_id(&row_id, RowMetaKey::DocumentId))
147+
Some(meta_id_from_row_id(row_id, RowMetaKey::DocumentId))
149148
}
150149

151150
/// If the row with given id not exist. It will return an empty row with given id.
@@ -159,14 +158,14 @@ impl Block {
159158
) -> Vec<Row> {
160159
let mut rows = Vec::new();
161160

162-
let row_ids: Vec<RowId> = row_orders.iter().map(|order| order.id.clone()).collect();
161+
let row_ids: Vec<RowId> = row_orders.iter().map(|order| order.id).collect();
163162
if let Ok(database_rows) = self.init_database_rows(row_ids, auto_fetch).await {
164163
for database_row in database_rows {
165164
let read_guard = database_row.read().await;
166-
let row_id = read_guard.row_id.clone();
165+
let row_id = read_guard.row_id;
167166
let row = read_guard
168167
.get_row()
169-
.unwrap_or_else(|| Row::empty(row_id, &self.database_id));
168+
.unwrap_or_else(|| Row::empty(row_id, self.database_id));
170169
rows.push(row);
171170
}
172171
}
@@ -195,7 +194,7 @@ impl Block {
195194

196195
/// Get the [DatabaseRow] from the cache. If the row is not in the cache, initialize it.
197196
pub fn init_database_row(&self, row_id: &RowId, ret: Option<InitRowChan>) {
198-
let row_id = row_id.clone();
197+
let row_id = *row_id;
199198
let row_change_tx = self.row_change_tx.clone();
200199
let collab_service = self.collab_service.clone();
201200
tokio::task::spawn(async move {
@@ -225,10 +224,9 @@ impl Block {
225224
auto_fetch: bool,
226225
) -> Result<Vec<Arc<RwLock<DatabaseRow>>>, DatabaseError> {
227226
// Retain only rows that are not in the cache
228-
let uncached_row_ids: Vec<String> = row_ids.iter().map(|id| id.to_string()).collect();
229227
let uncached_rows = self
230228
.collab_service
231-
.batch_build_arc_database_row(&uncached_row_ids, self.row_change_tx.clone(), auto_fetch)
229+
.batch_build_arc_database_row(&row_ids, self.row_change_tx.clone(), auto_fetch)
232230
.await?;
233231

234232
// Initialize final database rows by combining cached and newly fetched rows

0 commit comments

Comments
 (0)