From d0eaf13b6b9c521dbcf75a35ee81710956423ec0 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 26 Jun 2024 21:55:33 +0200 Subject: [PATCH] [backend] Code cleanup --- .../Mastodon/TimelineController.cs | 5 ++--- .../Controllers/TimelineController.cs | 3 +-- .../Core/Extensions/QueryableExtensions.cs | 19 +++++++++---------- Iceshrimp.Backend/Pages/QueueJob.cshtml.cs | 1 - 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Iceshrimp.Backend/Controllers/Mastodon/TimelineController.cs b/Iceshrimp.Backend/Controllers/Mastodon/TimelineController.cs index ec935625..dbceb1f3 100644 --- a/Iceshrimp.Backend/Controllers/Mastodon/TimelineController.cs +++ b/Iceshrimp.Backend/Controllers/Mastodon/TimelineController.cs @@ -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))] public async Task GetHomeTimeline(MastodonPaginationQuery query) { - var user = HttpContext.GetUserOrFail(); + var user = HttpContext.GetUserOrFail(); var res = await db.Notes .IncludeCommonProperties() diff --git a/Iceshrimp.Backend/Controllers/TimelineController.cs b/Iceshrimp.Backend/Controllers/TimelineController.cs index aedeed35..1163188c 100644 --- a/Iceshrimp.Backend/Controllers/TimelineController.cs +++ b/Iceshrimp.Backend/Controllers/TimelineController.cs @@ -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] diff --git a/Iceshrimp.Backend/Core/Extensions/QueryableExtensions.cs b/Iceshrimp.Backend/Core/Extensions/QueryableExtensions.cs index 9c112f39..df616141 100644 --- a/Iceshrimp.Backend/Core/Extensions/QueryableExtensions.cs +++ b/Iceshrimp.Backend/Core/Extensions/QueryableExtensions.cs @@ -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; @@ -178,7 +177,7 @@ public static class QueryableExtensions return Paginate(query, pq, filter.DefaultLimit, filter.MaxLimit); } - + public static IQueryable PaginateByOffset( this IQueryable query, MastodonPaginationQuery pq, @@ -191,7 +190,7 @@ public static class QueryableExtensions return query.Skip(pq.Offset ?? 0).Take(Math.Min(pq.Limit ?? defaultLimit, maxLimit)); } - + public static IQueryable PaginateByOffset( this IQueryable query, MastodonPaginationQuery pq, @@ -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,12 +616,12 @@ public static class QueryableExtensions public static IQueryable IncludeCommonProperties(this IQueryable 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 IncludeCommonProperties(this IQueryable query) { return query.Include(p => p.Note.User.UserProfile) @@ -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. } \ No newline at end of file diff --git a/Iceshrimp.Backend/Pages/QueueJob.cshtml.cs b/Iceshrimp.Backend/Pages/QueueJob.cshtml.cs index a6b739d3..f35c90da 100644 --- a/Iceshrimp.Backend/Pages/QueueJob.cshtml.cs +++ b/Iceshrimp.Backend/Pages/QueueJob.cshtml.cs @@ -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;