[backend] Code cleanup

This commit is contained in:
Laura Hausmann 2024-06-26 21:55:33 +02:00
parent c290c546f4
commit d0eaf13b6b
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
4 changed files with 12 additions and 16 deletions

View file

@ -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()

View file

@ -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]

View file

@ -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.
}

View file

@ -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;