Skip to content

Commit

Permalink
Merge pull request #783 from AppFlowy-IO/user-profile-improvement
Browse files Browse the repository at this point in the history
feat: use common table expression to improve user profile sql
  • Loading branch information
speed2exe authored Sep 3, 2024
2 parents b7c9336 + 236d972 commit 5fe1a87
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.

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

22 changes: 20 additions & 2 deletions libs/database/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,26 @@ pub async fn select_user_profile<'a, E: Executor<'a, Database = Postgres>>(
let user_profile = sqlx::query_as!(
AFUserProfileRow,
r#"
SELECT *
FROM public.af_user_profile_view WHERE uuid = $1
WITH af_user_row AS (
SELECT * FROM af_user WHERE uuid = $1
)
SELECT
af_user_row.uid,
af_user_row.uuid,
af_user_row.email,
af_user_row.password,
af_user_row.name,
af_user_row.metadata,
af_user_row.encryption_sign,
af_user_row.deleted_at,
af_user_row.updated_at,
af_user_row.created_at,
(SELECT workspace_id
FROM af_workspace_member
WHERE uid = af_user_row.uid
ORDER BY updated_at DESC
LIMIT 1) as latest_workspace_id
FROM af_user_row
"#,
user_uuid
)
Expand Down

0 comments on commit 5fe1a87

Please sign in to comment.