chore: opti log (#103)

* chore: opti log

* chore: clippy
This commit is contained in:
Nathan.fooo 2023-10-06 21:04:16 +08:00 committed by GitHub
parent 9918a6fe43
commit 17093de469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 33 additions and 10 deletions

View File

@ -71,6 +71,7 @@ services:
appflowy_cloud:
restart: on-failure
environment:
- RUST_LOG=trace
- APP_ENVIRONMENT=production
- APP__GOTRUE__JWT_SECRET=${GOTRUE_JWT_SECRET}
- APP__GOTRUE__EXT_URL=${API_EXTERNAL_URL}

View File

@ -163,7 +163,12 @@ where
let is_done = pending_msg.set_state(self.uid, MessageState::Done);
if is_done {
trace!("[Client {}]: Did send: {}:{}", self.uid, object_id, msg_id);
trace!(
"[Client {}]: did send oid:{}|msg_id{} ",
self.uid,
object_id,
msg_id
);
self.notify();
}
is_done

View File

@ -20,6 +20,7 @@ use shared_entity::dto::UserUpdateParams;
use shared_entity::dto::WorkspaceMembersParams;
use std::sync::Arc;
use std::time::SystemTime;
use tracing::instrument;
use gotrue_entity::{AccessTokenResponse, User};
@ -153,6 +154,7 @@ impl Client {
/// - `Ok(String)`: A `String` containing the constructed authorization URL if the specified provider is available.
/// - `Err(AppError)`: An `AppError` indicating either the OAuth provider is invalid or other issues occurred while fetching settings.
///
#[instrument(level = "debug", skip_all, err)]
pub async fn generate_oauth_url_with_provider(
&self,
provider: &OAuthProvider,
@ -172,6 +174,7 @@ impl Client {
/// Returns an OAuth URL by constructing the authorization URL for the specified provider.
/// The URL looks like, e.g., `appflowy-flutter://#access_token=...&expires_in=3600&provider_token=...&refresh_token=...&token_type=bearer`.
///
#[instrument(level = "debug", skip_all, err)]
pub async fn generate_sign_in_url_with_email(
&self,
admin_user_email: &str,
@ -210,6 +213,7 @@ impl Client {
Ok((user, is_new))
}
#[instrument(level = "debug", skip_all, err)]
#[inline]
async fn verify_token_cloud(&self, access_token: &str) -> Result<bool, AppError> {
let url = format!("{}/api/user/verify/{}", self.base_url, access_token);
@ -218,6 +222,7 @@ impl Client {
Ok(sign_in_resp.is_new)
}
#[instrument(level = "debug", skip_all, err)]
pub async fn create_magic_link(&self, email: &str, password: &str) -> Result<User, AppError> {
let user = self
.gotrue_client
@ -234,6 +239,7 @@ impl Client {
Ok(user)
}
#[instrument(level = "debug", skip_all, err)]
pub async fn create_email_verified_user(
&self,
email: &str,
@ -297,6 +303,7 @@ impl Client {
}
}
#[instrument(level = "debug", skip_all, err)]
pub async fn profile(&self) -> Result<AFUserProfileView, AppError> {
let url = format!("{}/api/user/profile", self.base_url);
let resp = self
@ -309,6 +316,7 @@ impl Client {
.into_data()
}
#[instrument(level = "debug", skip_all, err)]
pub async fn workspaces(&self) -> Result<AFWorkspaces, AppError> {
let url = format!("{}/api/workspace/list", self.base_url);
let resp = self
@ -321,6 +329,7 @@ impl Client {
.into_data()
}
#[instrument(level = "debug", skip_all, err)]
pub async fn get_workspace_members(
&self,
workspace_uuid: uuid::Uuid,
@ -339,6 +348,7 @@ impl Client {
.into_data()
}
#[instrument(level = "debug", skip_all, err)]
pub async fn add_workspace_members(
&self,
workspace_uuid: uuid::Uuid,
@ -359,6 +369,7 @@ impl Client {
Ok(())
}
#[instrument(level = "debug", skip_all, err)]
pub async fn remove_workspace_members(
&self,
workspace_uuid: uuid::Uuid,
@ -379,6 +390,7 @@ impl Client {
Ok(())
}
#[instrument(level = "debug", skip_all, err)]
pub async fn sign_in_password(&self, email: &str, password: &str) -> Result<bool, AppError> {
let access_token_resp = self
.gotrue_client
@ -399,6 +411,7 @@ impl Client {
/// This function attempts to refresh the access token by sending a request to the authentication server
/// using the stored refresh token. If successful, it updates the stored access token with the new one
/// received from the server.
#[instrument(level = "debug", skip_all, err)]
pub async fn refresh(&self) -> Result<(), AppError> {
let refresh_token = self
.token
@ -416,6 +429,7 @@ impl Client {
Ok(())
}
#[instrument(level = "debug", skip_all, err)]
pub async fn sign_up(&self, email: &str, password: &str) -> Result<(), AppError> {
match self.gotrue_client.sign_up(email, password).await? {
Authenticated(access_token_resp) => {
@ -429,11 +443,13 @@ impl Client {
}
}
#[instrument(level = "debug", skip_all, err)]
pub async fn sign_out(&self) -> Result<(), AppError> {
self.gotrue_client.logout(&self.access_token()?).await?;
Ok(())
}
#[instrument(level = "debug", skip_all, err)]
pub async fn update(&self, params: UserUpdateParams) -> Result<(), AppError> {
let updated_user = self
.gotrue_client
@ -448,6 +464,7 @@ impl Client {
Ok(())
}
#[instrument(level = "debug", skip_all, err)]
pub async fn update_user_name(&self, new_name: &str) -> Result<(), AppError> {
let url = format!("{}/api/user/update", self.base_url);
let params = UpdateUsernameParams {
@ -462,6 +479,7 @@ impl Client {
AppResponse::<()>::from_response(resp).await?.into_error()
}
#[instrument(level = "debug", skip_all, err)]
pub async fn create_collab(&self, params: InsertCollabParams) -> Result<(), AppError> {
let url = format!("{}/api/collab/", self.base_url);
let resp = self
@ -473,6 +491,7 @@ impl Client {
AppResponse::<()>::from_response(resp).await?.into_error()
}
#[instrument(level = "debug", skip_all, err)]
pub async fn update_collab(&self, params: InsertCollabParams) -> Result<(), AppError> {
let url = format!("{}/api/collab/", self.base_url);
let resp = self
@ -484,6 +503,7 @@ impl Client {
AppResponse::<()>::from_response(resp).await?.into_error()
}
#[instrument(level = "debug", skip_all, err)]
pub async fn get_collab(&self, params: QueryCollabParams) -> Result<RawData, AppError> {
let url = format!("{}/api/collab/", self.base_url);
let resp = self
@ -497,6 +517,7 @@ impl Client {
.into_data()
}
#[instrument(level = "debug", skip_all, err)]
pub async fn delete_collab(&self, params: DeleteCollabParams) -> Result<(), AppError> {
let url = format!("{}/api/collab/", self.base_url);
let resp = self

View File

@ -192,7 +192,7 @@ impl WSClient {
.channels
.write()
.entry(business_id)
.or_insert_with(HashMap::new)
.or_default()
.insert(object_id, Arc::downgrade(&channel));
Ok(channel)
}
@ -221,7 +221,6 @@ impl WSClient {
}
async fn set_state(&self, state: ConnectState) {
trace!("websocket state: {:?}", state);
self.state_notify.lock().set_state(state);
}
}

View File

@ -51,8 +51,6 @@ impl ServerFixIntervalPing {
loop {
tokio::select! {
_ = interval.tick() => {
// Send the ping
tracing::trace!("🟢ping from client");
let _ = sender.send(Message::Ping(vec![]));
if let Some(ping_count) = weak_ping_count.upgrade() {
let mut lock = ping_count.lock().await;
@ -67,7 +65,6 @@ impl ServerFixIntervalPing {
},
msg = receiver.recv() => {
if let Ok(Message::Pong(_)) = msg {
tracing::trace!("🟢pong from server");
if let Some(ping_count) = weak_ping_count.upgrade() {
let mut lock = ping_count.lock().await;
*lock = 0;

View File

@ -16,7 +16,7 @@ impl ConnectStateNotify {
pub(crate) fn set_state(&mut self, state: ConnectState) {
if self.state != state {
tracing::trace!("[🙂Client]: connect state changed to {:?}", state);
tracing::trace!("[WS]: {:?}", state);
self.state = state.clone();
let _ = self.sender.send(state);
}

View File

@ -1,6 +1,6 @@
#[derive(Debug, thiserror::Error)]
pub enum DatabaseError {
#[error("Record not found")]
#[error("Database not found")]
RecordNotFound,
#[error(transparent)]

View File

@ -26,7 +26,7 @@ impl AppError {
impl Display for AppError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.message)
f.write_fmt(format_args!("code:{} msg: {}", self.code, self.message))
}
}

View File

@ -43,5 +43,5 @@ fn name_from_user_metadata(value: &serde_json::Value) -> String {
.or(value.get("nickname"))
.and_then(serde_json::Value::as_str)
.map(str::to_string)
.unwrap_or(String::new())
.unwrap_or_default()
}