[backend] Code cleanup
This commit is contained in:
parent
c290c546f4
commit
d0eaf13b6b
4 changed files with 12 additions and 16 deletions
|
@ -8,7 +8,6 @@ using Iceshrimp.Backend.Core.Database;
|
|||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
using Iceshrimp.Backend.Core.Extensions;
|
||||
using Iceshrimp.Backend.Core.Middleware;
|
||||
using Iceshrimp.Backend.Core.Services;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
|
@ -23,14 +22,14 @@ namespace Iceshrimp.Backend.Controllers.Mastodon;
|
|||
[EnableRateLimiting("sliding")]
|
||||
[EnableCors("mastodon")]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
public class TimelineController(DatabaseContext db, NoteRenderer noteRenderer, CacheService cache) : ControllerBase
|
||||
public class TimelineController(DatabaseContext db, NoteRenderer noteRenderer) : ControllerBase
|
||||
{
|
||||
[Authorize("read:statuses")]
|
||||
[HttpGet("home")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<StatusEntity>))]
|
||||
public async Task<IActionResult> GetHomeTimeline(MastodonPaginationQuery query)
|
||||
{
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
|
||||
var res = await db.Notes
|
||||
.IncludeCommonProperties()
|
||||
|
|
|
@ -7,7 +7,6 @@ using Iceshrimp.Backend.Core.Database;
|
|||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
using Iceshrimp.Backend.Core.Extensions;
|
||||
using Iceshrimp.Backend.Core.Middleware;
|
||||
using Iceshrimp.Backend.Core.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
@ -19,7 +18,7 @@ namespace Iceshrimp.Backend.Controllers;
|
|||
[EnableRateLimiting("sliding")]
|
||||
[Route("/api/iceshrimp/timelines")]
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
public class TimelineController(DatabaseContext db, CacheService cache, NoteRenderer noteRenderer) : ControllerBase
|
||||
public class TimelineController(DatabaseContext db, NoteRenderer noteRenderer) : ControllerBase
|
||||
{
|
||||
[HttpGet("home")]
|
||||
[Authenticate]
|
||||
|
|
|
@ -9,7 +9,6 @@ using Iceshrimp.Backend.Controllers.Schemas;
|
|||
using Iceshrimp.Backend.Core.Database;
|
||||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
using Iceshrimp.Backend.Core.Middleware;
|
||||
using Iceshrimp.Backend.Core.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
@ -592,7 +591,7 @@ public static class QueryableExtensions
|
|||
return query.FilterByPublicTimelineRequest(request);
|
||||
}
|
||||
|
||||
#pragma warning disable CS8602 // Dereference of a possibly null reference.
|
||||
#pragma warning disable CS8602 // Dereference of a possibly null reference.
|
||||
// Justification: in the context of nullable EF navigation properties, null values are ignored and therefore irrelevant.
|
||||
// Source: https://learn.microsoft.com/en-us/ef/core/miscellaneous/nullable-reference-types#navigating-and-including-nullable-relationships
|
||||
|
||||
|
@ -617,10 +616,10 @@ public static class QueryableExtensions
|
|||
|
||||
public static IQueryable<NoteLike> IncludeCommonProperties(this IQueryable<NoteLike> query)
|
||||
{
|
||||
return query.Include(p => p.Note.User.UserProfile)
|
||||
.Include(p => p.Note.Renote.User.UserProfile)
|
||||
.Include(p => p.Note.Renote.Renote.User.UserProfile)
|
||||
.Include(p => p.Note.Reply.User.UserProfile);
|
||||
return query.Include(p => p.Note.User.UserProfile)
|
||||
.Include(p => p.Note.Renote.User.UserProfile)
|
||||
.Include(p => p.Note.Renote.Renote.User.UserProfile)
|
||||
.Include(p => p.Note.Reply.User.UserProfile);
|
||||
}
|
||||
|
||||
public static IQueryable<NoteBookmark> IncludeCommonProperties(this IQueryable<NoteBookmark> query)
|
||||
|
@ -643,5 +642,5 @@ public static class QueryableExtensions
|
|||
.Include(p => p.FollowRequest.Followee.UserProfile);
|
||||
}
|
||||
|
||||
#pragma warning restore CS8602 // Dereference of a possibly null reference.
|
||||
#pragma warning restore CS8602 // Dereference of a possibly null reference.
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
using Iceshrimp.Backend.Core.Database;
|
||||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
using Iceshrimp.Backend.Core.Middleware;
|
||||
using Iceshrimp.Backend.Core.Queues;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
|
Loading…
Add table
Reference in a new issue