Merge pull request #783 from AppFlowy-IO/user-profile-improvement
feat: use common table expression to improve user profile sql
This commit is contained in:
commit
5fe1a874c0
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "\n SELECT *\n FROM public.af_user_profile_view WHERE uuid = $1\n ",
|
"query": "\n WITH af_user_row AS (\n SELECT * FROM af_user WHERE uuid = $1\n )\n SELECT\n af_user_row.uid,\n af_user_row.uuid,\n af_user_row.email,\n af_user_row.password,\n af_user_row.name,\n af_user_row.metadata,\n af_user_row.encryption_sign,\n af_user_row.deleted_at,\n af_user_row.updated_at,\n af_user_row.created_at,\n (SELECT workspace_id\n FROM af_workspace_member\n WHERE uid = af_user_row.uid\n ORDER BY updated_at DESC\n LIMIT 1) as latest_workspace_id\n FROM af_user_row\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
|
|
@ -65,18 +65,18 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"nullable": [
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
true,
|
null
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "7438ddaf9ed9fab7ba4cb1b9c79ff541fa2e63a629cad4f8e9692a50a4e5e03c"
|
"hash": "a8443c8307a099fbfa3e04232fdc7719c28dc5acac088686e86980544fe4bbc9"
|
||||||
}
|
}
|
||||||
|
|
@ -584,8 +584,26 @@ pub async fn select_user_profile<'a, E: Executor<'a, Database = Postgres>>(
|
||||||
let user_profile = sqlx::query_as!(
|
let user_profile = sqlx::query_as!(
|
||||||
AFUserProfileRow,
|
AFUserProfileRow,
|
||||||
r#"
|
r#"
|
||||||
SELECT *
|
WITH af_user_row AS (
|
||||||
FROM public.af_user_profile_view WHERE uuid = $1
|
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
|
user_uuid
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue