[backend/api] Simplify GetAvatar and GetBanner database queries

This commit is contained in:
pancakes 2024-12-20 17:07:03 +10:00 committed by Laura Hausmann
parent b9cb72475d
commit f40c0e2499
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 5 additions and 13 deletions

View file

@ -127,11 +127,8 @@ public class ProfileController(
{
var user = HttpContext.GetUserOrFail();
var file = await db.Users
.IncludeCommonProperties()
.Where(p => p.Id == user.Id)
.Select(p => p.Avatar)
.FirstOrDefaultAsync()
var file = await db.DriveFiles
.FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserAvatar != null)
?? throw GracefulException.RecordNotFound();
return new DriveFileResponse
@ -200,11 +197,8 @@ public class ProfileController(
{
var user = HttpContext.GetUserOrFail();
var file = await db.Users
.IncludeCommonProperties()
.Where(p => p.Id == user.Id)
.Select(p => p.Banner)
.FirstOrDefaultAsync()
var file = await db.DriveFiles
.FirstOrDefaultAsync(p => p.UserId == user.Id && p.UserBanner != null)
?? throw GracefulException.RecordNotFound();
return new DriveFileResponse

View file

@ -714,9 +714,7 @@ public static class QueryableExtensions
public static IQueryable<User> IncludeCommonProperties(this IQueryable<User> query)
{
return query.Include(p => p.UserProfile)
.Include(p => p.Avatar)
.Include(p => p.Banner);
return query.Include(p => p.UserProfile);
}
public static IQueryable<Bite> IncludeCommonProperties(this IQueryable<Bite> query)