chore: refactor logs (#236)
* chore: add logs * chore: return ws state * fix: init the collab from disk
This commit is contained in:
parent
6b119fbf5b
commit
a455c9de8e
|
|
@ -819,7 +819,7 @@ impl Client {
|
|||
AppResponse::<()>::from_response(resp).await?.into_error()
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip_all, err)]
|
||||
#[instrument(level = "debug", skip_all)]
|
||||
pub async fn get_collab(
|
||||
&self,
|
||||
params: QueryCollabParams,
|
||||
|
|
|
|||
|
|
@ -310,6 +310,10 @@ impl WSClient {
|
|||
self.sender.clone()
|
||||
}
|
||||
|
||||
pub fn get_state(&self) -> ConnectState {
|
||||
self.state_notify.lock().state.clone()
|
||||
}
|
||||
|
||||
async fn set_state(&self, state: ConnectState) {
|
||||
self.state_notify.lock().set_state(state);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,8 +157,8 @@ pub async fn insert_into_af_collab(
|
|||
tracing::Level::TRACE,
|
||||
"did insert new collab row: {}:{}:{}",
|
||||
uid,
|
||||
workspace_id,
|
||||
params.object_id,
|
||||
workspace_id
|
||||
);
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ pub trait CollabStorage: Send + Sync + 'static {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `params` - The parameters required to query a collab object.
|
||||
/// * `force_from_disk` - If `true`, the data will be retrieved from the disk instead of the cache.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
|
|
@ -92,6 +93,7 @@ pub trait CollabStorage: Send + Sync + 'static {
|
|||
&self,
|
||||
uid: &i64,
|
||||
params: QueryCollabParams,
|
||||
force_from_disk: bool,
|
||||
) -> DatabaseResult<EncodedCollabV1>;
|
||||
|
||||
async fn batch_get_collab(
|
||||
|
|
@ -152,8 +154,12 @@ where
|
|||
&self,
|
||||
uid: &i64,
|
||||
params: QueryCollabParams,
|
||||
force_from_disk: bool,
|
||||
) -> DatabaseResult<EncodedCollabV1> {
|
||||
self.as_ref().get_collab_encoded_v1(uid, params).await
|
||||
self
|
||||
.as_ref()
|
||||
.get_collab_encoded_v1(uid, params, force_from_disk)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn batch_get_collab(
|
||||
|
|
@ -253,6 +259,7 @@ impl CollabStorage for CollabStoragePgImpl {
|
|||
&self,
|
||||
_uid: &i64,
|
||||
params: QueryCollabParams,
|
||||
_force_from_disk: bool,
|
||||
) -> DatabaseResult<EncodedCollabV1> {
|
||||
match collab_db_ops::select_blob_from_af_collab(
|
||||
&self.pg_pool,
|
||||
|
|
|
|||
|
|
@ -173,7 +173,11 @@ where
|
|||
async fn init(&self, object_id: &str, _origin: &CollabOrigin, doc: &Doc) {
|
||||
let params = QueryCollabParams::new(object_id, self.collab_type.clone(), &self.workspace_id);
|
||||
|
||||
match self.storage.get_collab_encoded_v1(&self.uid, params).await {
|
||||
match self
|
||||
.storage
|
||||
.get_collab_encoded_v1(&self.uid, params, true)
|
||||
.await
|
||||
{
|
||||
Ok(encoded_collab_v1) => match init_collab_with_raw_data(object_id, &encoded_collab_v1, doc)
|
||||
.await
|
||||
{
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@ async fn get_collab_handler(
|
|||
.map_err(AppResponseError::from)?;
|
||||
let data = state
|
||||
.collab_storage
|
||||
.get_collab_encoded_v1(&uid, payload.into_inner())
|
||||
.get_collab_encoded_v1(&uid, payload.into_inner(), false)
|
||||
.await
|
||||
.map_err(AppResponseError::from)?;
|
||||
|
||||
|
|
@ -325,6 +325,7 @@ async fn create_collab_snapshot_handler(
|
|||
.get_collab_encoded_v1(
|
||||
&uid,
|
||||
QueryCollabParams::new(&object_id, collab_type, &workspace_id),
|
||||
false,
|
||||
)
|
||||
.await?
|
||||
.encode_to_bytes()
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ impl CollabAccessControl for CasbinCollabAccessControl {
|
|||
|
||||
access_level.ok_or(AppError::RecordNotFound(format!(
|
||||
"collab:{} does not exist or user:{} is not a member",
|
||||
uid, oid
|
||||
oid, uid
|
||||
)))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ pub(crate) async fn enforcer_update(
|
|||
}?;
|
||||
|
||||
let mut enforcer = enforcer.write().await;
|
||||
// TODO(jireh): if the policy already exists and doesn't need to be updated, return early.
|
||||
enforcer_remove(&mut enforcer, uid, obj).await?;
|
||||
event!(
|
||||
tracing::Level::INFO,
|
||||
|
|
|
|||
|
|
@ -24,15 +24,23 @@ where
|
|||
C: CollabAccessControl,
|
||||
{
|
||||
for params in params_list {
|
||||
if !params.override_if_exist
|
||||
&& database::collab::collab_exists(pg_pool, ¶ms.object_id).await?
|
||||
{
|
||||
// When calling this function, the caller should have already checked if the collab exists.
|
||||
return Err(AppError::RecordAlreadyExists(format!(
|
||||
"Collab with object_id {} already exists",
|
||||
params.object_id
|
||||
)));
|
||||
if database::collab::collab_exists(pg_pool, ¶ms.object_id).await? {
|
||||
if params.override_if_exist {
|
||||
event!(
|
||||
tracing::Level::INFO,
|
||||
"Collab:{} with object_id {} already exists, override it",
|
||||
params.collab_type,
|
||||
params.object_id
|
||||
);
|
||||
} else {
|
||||
// When calling this function, the caller should have already checked if the collab exists.
|
||||
return Err(AppError::RecordAlreadyExists(format!(
|
||||
"Collab:{} with object_id {} already exists",
|
||||
params.collab_type, params.object_id
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
collab_access_control
|
||||
.cache_collab_access_level(
|
||||
CollabUserId::UserUuid(user_uuid),
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@ where
|
|||
&self,
|
||||
uid: &i64,
|
||||
params: QueryCollabParams,
|
||||
force_from_disk: bool,
|
||||
) -> DatabaseResult<EncodedCollabV1> {
|
||||
params.validate()?;
|
||||
self
|
||||
|
|
@ -153,12 +154,16 @@ where
|
|||
.get_collab_access_level(uid, ¶ms.object_id)
|
||||
.await?;
|
||||
|
||||
let collab = self
|
||||
.collab_by_object_id
|
||||
.read()
|
||||
.await
|
||||
.get(¶ms.object_id)
|
||||
.and_then(|collab| collab.upgrade());
|
||||
let collab = if force_from_disk {
|
||||
None
|
||||
} else {
|
||||
self
|
||||
.collab_by_object_id
|
||||
.read()
|
||||
.await
|
||||
.get(¶ms.object_id)
|
||||
.and_then(|collab| collab.upgrade())
|
||||
};
|
||||
|
||||
match collab {
|
||||
None => {
|
||||
|
|
@ -167,7 +172,7 @@ where
|
|||
"Get collab data:{} from disk",
|
||||
params.object_id
|
||||
);
|
||||
self.inner.get_collab_encoded_v1(uid, params).await
|
||||
self.inner.get_collab_encoded_v1(uid, params, true).await
|
||||
},
|
||||
Some(collab) => {
|
||||
event!(
|
||||
|
|
|
|||
Loading…
Reference in New Issue