[backend/core] Fix UpdateProfileMentions early return codepath

This commit is contained in:
Laura Hausmann 2024-02-26 21:31:33 +01:00
parent 341a4a8ee5
commit 7c801bfa89
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -182,7 +182,7 @@ public class UserService(
var processPendingDeletes = await ResolveAvatarAndBanner(user, actor); var processPendingDeletes = await ResolveAvatarAndBanner(user, actor);
await db.SaveChangesAsync(); await db.SaveChangesAsync();
await processPendingDeletes(); await processPendingDeletes();
await UpdateProfileMentions(user, actor); user = await UpdateProfileMentions(user, actor);
return user; return user;
} }
catch (UniqueConstraintException) catch (UniqueConstraintException)
@ -289,7 +289,7 @@ public class UserService(
db.Update(user); db.Update(user);
await db.SaveChangesAsync(); await db.SaveChangesAsync();
await processPendingDeletes(); await processPendingDeletes();
await UpdateProfileMentions(user, actor, force: true); user = await UpdateProfileMentions(user, actor, force: true);
return user; return user;
} }
@ -624,10 +624,10 @@ public class UserService(
[SuppressMessage("ReSharper", "EntityFramework.NPlusOne.IncompleteDataQuery", Justification = "Projectables")] [SuppressMessage("ReSharper", "EntityFramework.NPlusOne.IncompleteDataQuery", Justification = "Projectables")]
[SuppressMessage("ReSharper", "EntityFramework.NPlusOne.IncompleteDataUsage", Justification = "Same as above")] [SuppressMessage("ReSharper", "EntityFramework.NPlusOne.IncompleteDataUsage", Justification = "Same as above")]
[SuppressMessage("ReSharper", "SuggestBaseTypeForParameter", Justification = "Method only makes sense for users")] [SuppressMessage("ReSharper", "SuggestBaseTypeForParameter", Justification = "Method only makes sense for users")]
private async Task UpdateProfileMentions(User user, ASActor? actor, bool force = false) private async Task<User> UpdateProfileMentions(User user, ASActor? actor, bool force = false)
{ {
if (followupTaskSvc.IsBackgroundWorker && !force) return; if (followupTaskSvc.IsBackgroundWorker && !force) return user;
if (KeyedLocker.IsInUse($"profileMentions:{user.Id}")) return; if (KeyedLocker.IsInUse($"profileMentions:{user.Id}")) return user;
var task = followupTaskSvc.ExecuteTask("UpdateProfileMentionsInBackground", async provider => var task = followupTaskSvc.ExecuteTask("UpdateProfileMentionsInBackground", async provider =>
{ {
@ -674,5 +674,6 @@ public class UserService(
}); });
await task.SafeWaitAsync(TimeSpan.FromMilliseconds(500)); await task.SafeWaitAsync(TimeSpan.FromMilliseconds(500));
return user;
} }
} }