From 4448e0033376d8f9695660bafa0dc6a9633285ce Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 27 Sep 2024 03:00:36 +0200 Subject: [PATCH] [backend/core] Fix erroneous attempts to compute instance stats for local instance when creating follow relationship between local users --- .../Core/Services/UserService.cs | 49 +++++++++++-------- .../Schemas/Web/MigrationSchemas.cs | 6 +++ 2 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 Iceshrimp.Shared/Schemas/Web/MigrationSchemas.cs diff --git a/Iceshrimp.Backend/Core/Services/UserService.cs b/Iceshrimp.Backend/Core/Services/UserService.cs index b9b99505..0e862729 100644 --- a/Iceshrimp.Backend/Core/Services/UserService.cs +++ b/Iceshrimp.Backend/Core/Services/UserService.cs @@ -726,11 +726,14 @@ public class UserService( // Followee has auto accept enabled & is already following the follower user if (autoAccept) { - if (requestId == null) - throw new Exception("requestId must not be null at this stage"); + if (follower.IsRemoteUser) + { + if (requestId == null) + throw new Exception("requestId must not be null at this stage"); - var activity = activityRenderer.RenderAccept(followee, follower, requestId); - await deliverSvc.DeliverToAsync(activity, followee, follower); + var activity = activityRenderer.RenderAccept(followee, follower, requestId); + await deliverSvc.DeliverToAsync(activity, followee, follower); + } var following = new Following { @@ -757,15 +760,18 @@ public class UserService( .ExecuteUpdateAsync(p => p.SetProperty(i => i.FollowersCount, i => i.FollowersCount + 1)); - _ = followupTaskSvc.ExecuteTask("IncrementInstanceIncomingFollowsCounter", async provider => + if (follower.IsRemoteUser) { - var bgDb = provider.GetRequiredService(); - var bgInstanceSvc = provider.GetRequiredService(); - var dbInstance = await bgInstanceSvc.GetUpdatedInstanceMetadataAsync(follower); - await bgDb.Instances.Where(p => p.Id == dbInstance.Id) - .ExecuteUpdateAsync(p => p.SetProperty(i => i.IncomingFollows, - i => i.IncomingFollows + 1)); - }); + _ = followupTaskSvc.ExecuteTask("IncrementInstanceIncomingFollowsCounter", async provider => + { + var bgDb = provider.GetRequiredService(); + var bgInstanceSvc = provider.GetRequiredService(); + var dbInstance = await bgInstanceSvc.GetUpdatedInstanceMetadataAsync(follower); + await bgDb.Instances.Where(p => p.Id == dbInstance.Id) + .ExecuteUpdateAsync(p => p.SetProperty(i => i.IncomingFollows, + i => i.IncomingFollows + 1)); + }); + } return; } @@ -821,15 +827,18 @@ public class UserService( await db.Users.Where(p => p.Id == followee.Id) .ExecuteUpdateAsync(p => p.SetProperty(i => i.FollowersCount, i => i.FollowersCount + 1)); - _ = followupTaskSvc.ExecuteTask("IncrementInstanceIncomingFollowsCounter", async provider => + if (follower.IsRemoteUser) { - var bgDb = provider.GetRequiredService(); - var bgInstanceSvc = provider.GetRequiredService(); - var dbInstance = await bgInstanceSvc.GetUpdatedInstanceMetadataAsync(follower); - await bgDb.Instances.Where(p => p.Id == dbInstance.Id) - .ExecuteUpdateAsync(p => p.SetProperty(i => i.IncomingFollows, - i => i.IncomingFollows + 1)); - }); + _ = followupTaskSvc.ExecuteTask("IncrementInstanceIncomingFollowsCounter", async provider => + { + var bgDb = provider.GetRequiredService(); + var bgInstanceSvc = provider.GetRequiredService(); + var dbInstance = await bgInstanceSvc.GetUpdatedInstanceMetadataAsync(follower); + await bgDb.Instances.Where(p => p.Id == dbInstance.Id) + .ExecuteUpdateAsync(p => p.SetProperty(i => i.IncomingFollows, + i => i.IncomingFollows + 1)); + }); + } } // If follower is remote, send an accept activity diff --git a/Iceshrimp.Shared/Schemas/Web/MigrationSchemas.cs b/Iceshrimp.Shared/Schemas/Web/MigrationSchemas.cs new file mode 100644 index 00000000..5fd28a59 --- /dev/null +++ b/Iceshrimp.Shared/Schemas/Web/MigrationSchemas.cs @@ -0,0 +1,6 @@ +namespace Iceshrimp.Shared.Schemas.Web; + +public class MigrationSchemas +{ + +} \ No newline at end of file