[backend/core] Fix erroneous attempts to compute instance stats for local instance when creating follow relationship between local users

This commit is contained in:
Laura Hausmann 2024-09-27 03:00:36 +02:00
parent f2bf80100d
commit 4448e00333
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 35 additions and 20 deletions

View file

@ -726,11 +726,14 @@ public class UserService(
// Followee has auto accept enabled & is already following the follower user // Followee has auto accept enabled & is already following the follower user
if (autoAccept) if (autoAccept)
{ {
if (requestId == null) if (follower.IsRemoteUser)
throw new Exception("requestId must not be null at this stage"); {
if (requestId == null)
throw new Exception("requestId must not be null at this stage");
var activity = activityRenderer.RenderAccept(followee, follower, requestId); var activity = activityRenderer.RenderAccept(followee, follower, requestId);
await deliverSvc.DeliverToAsync(activity, followee, follower); await deliverSvc.DeliverToAsync(activity, followee, follower);
}
var following = new Following var following = new Following
{ {
@ -757,15 +760,18 @@ public class UserService(
.ExecuteUpdateAsync(p => p.SetProperty(i => i.FollowersCount, .ExecuteUpdateAsync(p => p.SetProperty(i => i.FollowersCount,
i => i.FollowersCount + 1)); i => i.FollowersCount + 1));
_ = followupTaskSvc.ExecuteTask("IncrementInstanceIncomingFollowsCounter", async provider => if (follower.IsRemoteUser)
{ {
var bgDb = provider.GetRequiredService<DatabaseContext>(); _ = followupTaskSvc.ExecuteTask("IncrementInstanceIncomingFollowsCounter", async provider =>
var bgInstanceSvc = provider.GetRequiredService<InstanceService>(); {
var dbInstance = await bgInstanceSvc.GetUpdatedInstanceMetadataAsync(follower); var bgDb = provider.GetRequiredService<DatabaseContext>();
await bgDb.Instances.Where(p => p.Id == dbInstance.Id) var bgInstanceSvc = provider.GetRequiredService<InstanceService>();
.ExecuteUpdateAsync(p => p.SetProperty(i => i.IncomingFollows, var dbInstance = await bgInstanceSvc.GetUpdatedInstanceMetadataAsync(follower);
i => i.IncomingFollows + 1)); await bgDb.Instances.Where(p => p.Id == dbInstance.Id)
}); .ExecuteUpdateAsync(p => p.SetProperty(i => i.IncomingFollows,
i => i.IncomingFollows + 1));
});
}
return; return;
} }
@ -821,15 +827,18 @@ public class UserService(
await db.Users.Where(p => p.Id == followee.Id) await db.Users.Where(p => p.Id == followee.Id)
.ExecuteUpdateAsync(p => p.SetProperty(i => i.FollowersCount, i => i.FollowersCount + 1)); .ExecuteUpdateAsync(p => p.SetProperty(i => i.FollowersCount, i => i.FollowersCount + 1));
_ = followupTaskSvc.ExecuteTask("IncrementInstanceIncomingFollowsCounter", async provider => if (follower.IsRemoteUser)
{ {
var bgDb = provider.GetRequiredService<DatabaseContext>(); _ = followupTaskSvc.ExecuteTask("IncrementInstanceIncomingFollowsCounter", async provider =>
var bgInstanceSvc = provider.GetRequiredService<InstanceService>(); {
var dbInstance = await bgInstanceSvc.GetUpdatedInstanceMetadataAsync(follower); var bgDb = provider.GetRequiredService<DatabaseContext>();
await bgDb.Instances.Where(p => p.Id == dbInstance.Id) var bgInstanceSvc = provider.GetRequiredService<InstanceService>();
.ExecuteUpdateAsync(p => p.SetProperty(i => i.IncomingFollows, var dbInstance = await bgInstanceSvc.GetUpdatedInstanceMetadataAsync(follower);
i => i.IncomingFollows + 1)); 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 // If follower is remote, send an accept activity

View file

@ -0,0 +1,6 @@
namespace Iceshrimp.Shared.Schemas.Web;
public class MigrationSchemas
{
}