Optimize database calls across multiple components by implementing Promise.all for parallel fetching of data, enhancing performance and reducing loading times.
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 2m40s

This commit is contained in:
Julien Froidefond
2025-12-16 11:19:54 +01:00
parent a9a4120874
commit ffbf3cd42f
8 changed files with 162 additions and 120 deletions

View File

@@ -12,31 +12,30 @@ export default async function ProfilePage() {
redirect("/login");
}
const user = await userService.getUserById(session.user.id, {
id: true,
email: true,
username: true,
avatar: true,
bio: true,
characterClass: true,
hp: true,
maxHp: true,
xp: true,
maxXp: true,
level: true,
score: true,
createdAt: true,
});
// Paralléliser les appels DB
const [user, backgroundImage] = await Promise.all([
userService.getUserById(session.user.id, {
id: true,
email: true,
username: true,
avatar: true,
bio: true,
characterClass: true,
hp: true,
maxHp: true,
xp: true,
maxXp: true,
level: true,
score: true,
createdAt: true,
}),
getBackgroundImage("home", "/got-background.jpg"),
]);
if (!user) {
redirect("/login");
}
const backgroundImage = await getBackgroundImage(
"home",
"/got-background.jpg"
);
// Convert Date to string for the component
const userProfile = {
...user,