From d965653972ba9a004b14b55bbe53fc1f17345fc7 Mon Sep 17 00:00:00 2001 From: Kopper Date: Wed, 18 Dec 2024 16:01:59 +0300 Subject: [PATCH] [backend] Backfill users on incoming follow --- .../Core/Services/UserService.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Iceshrimp.Backend/Core/Services/UserService.cs b/Iceshrimp.Backend/Core/Services/UserService.cs index a575a4b1..de042d97 100644 --- a/Iceshrimp.Backend/Core/Services/UserService.cs +++ b/Iceshrimp.Backend/Core/Services/UserService.cs @@ -786,6 +786,8 @@ public class UserService( if (follower.IsRemoteUser) { + await EnqueueBackfillTaskAsync(follower); + // @formatter:off _ = followupTaskSvc.ExecuteTaskAsync("IncrementInstanceIncomingFollowsCounter", async provider => { @@ -820,6 +822,8 @@ public class UserService( await db.AddAsync(request); await db.SaveChangesAsync(); await notificationSvc.GenerateFollowRequestReceivedNotificationAsync(request); + + if (follower.IsRemoteUser) await EnqueueBackfillTaskAsync(follower); } } } @@ -854,6 +858,8 @@ public class UserService( if (follower.IsRemoteUser) { + await EnqueueBackfillTaskAsync(follower); + _ = followupTaskSvc.ExecuteTaskAsync("IncrementInstanceIncomingFollowsCounter", async provider => { var bgDb = provider.GetRequiredService(); @@ -886,17 +892,13 @@ public class UserService( if (!cfg.Enabled) return; // don't try to schedule a backfill for local users - if (user.Host == null) return; + if (user.IsLocalUser) return; // we don't need to backfill anyone we have followers for since we'll get their posts delivered to us - var needBackfill = await db.Users - .AnyAsync(u => u.Id == user.Id - && !u.Followers.Any() - && u.Outbox != null - && (u.OutboxFetchedAt == null || u.OutboxFetchedAt <= DateTime.UtcNow - cfg.RefreshAfterTimeSpan)); - - // only queue if the user's backfill timestamp got updated. if it didn't, it means this user doesn't need backfilling - // (or the thread doesn't exist, which shouldn't be possible) + var needBackfill = await db.Users.AnyAsync(u => u.Id == user.Id + && !u.Followers.Any() + && u.Outbox != null + && (u.OutboxFetchedAt == null || u.OutboxFetchedAt <= DateTime.UtcNow - cfg.RefreshAfterTimeSpan)); if (!needBackfill) return; var jobData = new BackfillUserJobData