Add show_on_profile to UserAchievement
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA
What does this MR do and why?
Add show_on_profile to UserAchievement
Currently, all awarded achievements are shown on the profile of a user. With this change, users can now decide, which achievements they want to show on their profile.
Related to #390389
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Backend only changes.
Database queries
Updating user achievement
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/30585/commands/94822
UPDATE
"user_achievements"
SET
"updated_at" = '2024-08-03 14:27:35.151732',
"show_on_profile" = FALSE
WHERE
"user_achievements"."id" = 9
ModifyTable on public.user_achievements (cost=0.28..3.30 rows=0 width=0) (actual time=9.571..9.572 rows=0 loops=1)
Buffers: shared hit=53 read=12 dirtied=7
I/O Timings: read=7.678 write=0.000
-> Index Scan using user_achievements_pkey on public.user_achievements (cost=0.28..3.30 rows=1 width=15) (actual time=2.767..2.769 rows=1 loops=1)
Index Cond: (user_achievements.id = 9)
Buffers: shared hit=3 read=3
I/O Timings: read=2.690 write=0.000
Querying user achievements (includeHidden: true)
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/30585/commands/94819
SELECT
"user_achievements".*
FROM
"user_achievements"
WHERE
"user_achievements"."user_id" = 1
AND "user_achievements"."revoked_by_user_id" IS NULL
ORDER BY
"user_achievements"."priority" ASC,
"user_achievements"."id" ASC
LIMIT 101
Limit (cost=4.83..4.84 rows=2 width=76) (actual time=3.807..3.809 rows=2 loops=1)
Buffers: shared hit=9 read=4
I/O Timings: read=3.708 write=0.000
-> Sort (cost=4.83..4.84 rows=2 width=76) (actual time=3.805..3.806 rows=2 loops=1)
Sort Key: user_achievements.priority, user_achievements.id
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=9 read=4
I/O Timings: read=3.708 write=0.000
-> Index Scan using index_user_achievements_on_user_id_revoked_by_is_null on public.user_achievements (cost=0.28..4.82 rows=2 width=76) (actual time=2.855..3.754 rows=2 loops=1)
Index Cond: ((user_achievements.user_id = 1) AND ((user_achievements.revoked_by_user_id IS NULL) = true))
Buffers: shared hit=3 read=4
I/O Timings: read=3.708 write=0.000
Querying user achievements (includeHidden: false)
https://console.postgres.ai/gitlab/gitlab-production-main/sessions/30585/commands/94821
SELECT
"user_achievements".*
FROM
"user_achievements"
WHERE
"user_achievements"."user_id" = 1
AND "user_achievements"."revoked_by_user_id" IS NULL
AND "user_achievements"."show_on_profile" = TRUE
ORDER BY
"user_achievements"."priority" ASC,
"user_achievements"."id" ASC
LIMIT 101
Limit (cost=4.83..4.84 rows=1 width=77) (actual time=0.070..0.071 rows=2 loops=1)
Buffers: shared hit=13
I/O Timings: read=0.000 write=0.000
-> Sort (cost=4.83..4.84 rows=1 width=77) (actual time=0.068..0.069 rows=2 loops=1)
Sort Key: user_achievements.priority, user_achievements.id
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=13
I/O Timings: read=0.000 write=0.000
-> Index Scan using index_user_achievements_on_user_id_revoked_by_is_null on public.user_achievements (cost=0.28..4.82 rows=1 width=77) (actual time=0.022..0.024 rows=2 loops=1)
Index Cond: ((user_achievements.user_id = 1) AND ((user_achievements.revoked_by_user_id IS NULL) = true))
Filter: user_achievements.show_on_profile
Rows Removed by Filter: 0
Buffers: shared hit=7
I/O Timings: read=0.000 write=0.000
How to set up and validate locally
- Enable achievements:
Feature.enable(:achievements)
- Visit /root to see that there are three achievements
- Visit /-/graphql-explorer in a second tab and paste the query from below
- Execute the
achievements
query and verify that all haveshowOnProfile: true
- Execute the
updateShowOnProfile
mutation and verify that the correct one now hasshowOnProfile: false
(you might need to change the IDs) - Reload the profile page of
root
and verify that there are only two achievements shown
query achievements {
user(username: "root") {
userAchievements(includeHidden: true) {
nodes {
id
showOnProfile
}
}
}
}
mutation updateShowOnProfile {
userAchievementsUpdate(input: {
userAchievementId: "gid://gitlab/Achievements::UserAchievement/9"
showOnProfile: false
}) {
userAchievement {
id
showOnProfile
}
errors
}
}
Edited by Jerry Seto