[backend/masto-client] Include navigation properties for note queries
This commit is contained in:
parent
f230d95b5b
commit
a3fd46bb96
2 changed files with 11 additions and 0 deletions
|
@ -27,6 +27,7 @@ public class MastodonTimelineController(DatabaseContext db, NoteRenderer noteRen
|
||||||
public async Task<IActionResult> GetHomeTimeline() {
|
public async Task<IActionResult> GetHomeTimeline() {
|
||||||
var user = HttpContext.GetOauthUser() ?? throw new GracefulException("Failed to get user from HttpContext");
|
var user = HttpContext.GetOauthUser() ?? throw new GracefulException("Failed to get user from HttpContext");
|
||||||
var notes = await db.Notes
|
var notes = await db.Notes
|
||||||
|
.WithIncludes()
|
||||||
.IsFollowedBy(user)
|
.IsFollowedBy(user)
|
||||||
.OrderByIdDesc()
|
.OrderByIdDesc()
|
||||||
.Take(40)
|
.Take(40)
|
||||||
|
@ -41,6 +42,7 @@ public class MastodonTimelineController(DatabaseContext db, NoteRenderer noteRen
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<Status>))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<Status>))]
|
||||||
public async Task<IActionResult> GetPublicTimeline() {
|
public async Task<IActionResult> GetPublicTimeline() {
|
||||||
var notes = await db.Notes
|
var notes = await db.Notes
|
||||||
|
.WithIncludes()
|
||||||
.HasVisibility(Note.NoteVisibility.Public)
|
.HasVisibility(Note.NoteVisibility.Public)
|
||||||
.OrderByIdDesc()
|
.OrderByIdDesc()
|
||||||
.Take(40)
|
.Take(40)
|
||||||
|
|
|
@ -1,8 +1,17 @@
|
||||||
using Iceshrimp.Backend.Core.Database.Tables;
|
using Iceshrimp.Backend.Core.Database.Tables;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Iceshrimp.Backend.Core.Helpers;
|
namespace Iceshrimp.Backend.Core.Helpers;
|
||||||
|
|
||||||
public static class QueryHelpers {
|
public static class QueryHelpers {
|
||||||
|
public static IQueryable<Note> WithIncludes(this IQueryable<Note> query) {
|
||||||
|
return query.Include(p => p.User)
|
||||||
|
.Include(p => p.Renote)
|
||||||
|
.ThenInclude(p => p != null ? p.User : null)
|
||||||
|
.Include(p => p.Reply)
|
||||||
|
.ThenInclude(p => p != null ? p.User : null);
|
||||||
|
}
|
||||||
|
|
||||||
public static IQueryable<Note> HasVisibility(this IQueryable<Note> query, Note.NoteVisibility visibility) {
|
public static IQueryable<Note> HasVisibility(this IQueryable<Note> query, Note.NoteVisibility visibility) {
|
||||||
return query.Where(note => note.Visibility == visibility);
|
return query.Where(note => note.Visibility == visibility);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue