Skip to content

Commit

Permalink
Merge branch 'main' into stateless
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed Dec 24, 2024
2 parents 837f4de + 1131818 commit 1a5c171
Show file tree
Hide file tree
Showing 56 changed files with 2,395 additions and 362 deletions.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 53 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ base64.workspace = true
md5.workspace = true
nanoid = "0.4.0"
http.workspace = true
indexer.workspace = true

[dev-dependencies]
flate2 = "1.0"
Expand All @@ -177,7 +178,6 @@ collab-rt-entity = { path = "libs/collab-rt-entity" }
hex = "0.4.3"
unicode-normalization = "0.1.24"


[[bin]]
name = "appflowy_cloud"
path = "src/main.rs"
Expand Down Expand Up @@ -221,9 +221,11 @@ members = [
"xtask",
"libs/tonic-proto",
"libs/mailer",
"libs/indexer",
]

[workspace.dependencies]
indexer = { path = "libs/indexer" }
collab-rt-entity = { path = "libs/collab-rt-entity" }
collab-rt-protocol = { path = "libs/collab-rt-protocol" }
database = { path = "libs/database" }
Expand Down
1 change: 1 addition & 0 deletions deploy.env
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ APPFLOWY_LOCAL_AI_TEST_ENABLED=false
APPFLOWY_INDEXER_ENABLED=true
APPFLOWY_INDEXER_DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
APPFLOWY_INDEXER_REDIS_URL=redis://${REDIS_HOST}:${REDIS_PORT}
APPFLOWY_INDEXER_EMBEDDING_BUFFER_SIZE=5000

# AppFlowy Collaborate
APPFLOWY_COLLABORATE_MULTI_THREAD=false
Expand Down
1 change: 1 addition & 0 deletions dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ APPFLOWY_LOCAL_AI_TEST_ENABLED=false
APPFLOWY_INDEXER_ENABLED=true
APPFLOWY_INDEXER_DATABASE_URL=postgres://postgres:password@postgres:5432/postgres
APPFLOWY_INDEXER_REDIS_URL=redis://redis:6379
APPFLOWY_INDEXER_EMBEDDING_BUFFER_SIZE=5000

# AppFlowy Collaborate
APPFLOWY_COLLABORATE_MULTI_THREAD=false
Expand Down
6 changes: 6 additions & 0 deletions libs/app-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ pub enum AppError {
#[error("Decode update error: {0}")]
DecodeUpdateError(String),

#[error("{0}")]
ActionTimeout(String),

#[error("Apply update error:{0}")]
ApplyUpdateError(String),
}
Expand Down Expand Up @@ -263,6 +266,7 @@ impl AppError {
AppError::ServiceTemporaryUnavailable(_) => ErrorCode::ServiceTemporaryUnavailable,
AppError::DecodeUpdateError(_) => ErrorCode::DecodeUpdateError,
AppError::ApplyUpdateError(_) => ErrorCode::ApplyUpdateError,
AppError::ActionTimeout(_) => ErrorCode::ActionTimeout,
}
}
}
Expand Down Expand Up @@ -316,6 +320,7 @@ impl From<sqlx::Error> for AppError {
sqlx::Error::RowNotFound => {
AppError::RecordNotFound(format!("Record not exist in db. {})", msg))
},
sqlx::Error::PoolTimedOut => AppError::ActionTimeout(value.to_string()),
_ => AppError::SqlxError(msg),
}
}
Expand Down Expand Up @@ -424,6 +429,7 @@ pub enum ErrorCode {
ServiceTemporaryUnavailable = 1054,
DecodeUpdateError = 1055,
ApplyUpdateError = 1056,
ActionTimeout = 1057,
}

impl ErrorCode {
Expand Down
23 changes: 4 additions & 19 deletions libs/collab-rt-protocol/src/data_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ use collab::preclude::Collab;
use collab_entity::CollabType;
use tracing::instrument;

#[instrument(level = "trace", skip(data), fields(len = %data.len()))]
#[inline]
pub async fn spawn_blocking_validate_encode_collab(
object_id: &str,
data: &[u8],
collab_type: &CollabType,
) -> Result<(), Error> {
let collab_type = collab_type.clone();
pub async fn collab_from_encode_collab(object_id: &str, data: &[u8]) -> Result<Collab, Error> {
let object_id = object_id.to_string();
let data = data.to_vec();

Expand All @@ -27,28 +21,19 @@ pub async fn spawn_blocking_validate_encode_collab(
false,
)?;

collab_type.validate_require_data(&collab)?;
Ok::<(), Error>(())
Ok::<_, Error>(collab)
})
.await?
}

#[instrument(level = "trace", skip(data), fields(len = %data.len()))]
#[inline]
pub fn validate_encode_collab(
pub async fn validate_encode_collab(
object_id: &str,
data: &[u8],
collab_type: &CollabType,
) -> Result<(), Error> {
let encoded_collab = EncodedCollab::decode_from_bytes(data)?;
let collab = Collab::new_with_source(
CollabOrigin::Empty,
object_id,
DataSource::DocStateV1(encoded_collab.doc_state.to_vec()),
vec![],
false,
)?;

let collab = collab_from_encode_collab(object_id, data).await?;
collab_type.validate_require_data(&collab)?;
Ok::<(), Error>(())
}
Loading

0 comments on commit 1a5c171

Please sign in to comment.