[backend/core] Improve resolution of notes with pending reply/renote targets on note create
This fixes missing metadata (reply/renote user id/host), as well as stale reply/renote counts for replies/renotes processed out of order.
This commit is contained in:
parent
3d15ed6807
commit
6fdc8b73f7
1 changed files with 46 additions and 13 deletions
|
@ -234,24 +234,57 @@ public class NoteService(
|
||||||
_ = followupTaskSvc.ExecuteTask("ResolvePendingReplyRenoteTargets", async provider =>
|
_ = followupTaskSvc.ExecuteTask("ResolvePendingReplyRenoteTargets", async provider =>
|
||||||
{
|
{
|
||||||
var bgDb = provider.GetRequiredService<DatabaseContext>();
|
var bgDb = provider.GetRequiredService<DatabaseContext>();
|
||||||
|
var count = 0;
|
||||||
|
|
||||||
if (uri != null)
|
if (uri != null)
|
||||||
{
|
{
|
||||||
|
count +=
|
||||||
await bgDb.Notes.Where(p => p.ReplyUri == uri)
|
await bgDb.Notes.Where(p => p.ReplyUri == uri)
|
||||||
.ExecuteUpdateAsync(p => p.SetProperty(i => i.ReplyId, _ => note.Id)
|
.ExecuteUpdateAsync(p => p.SetProperty(i => i.ReplyUri, _ => null)
|
||||||
.SetProperty(i => i.ReplyUri, _ => null));
|
.SetProperty(i => i.ReplyId, _ => note.Id)
|
||||||
|
.SetProperty(i => i.ReplyUserId, _ => note.UserId)
|
||||||
|
.SetProperty(i => i.ReplyUserHost, _ => note.UserHost)
|
||||||
|
.SetProperty(i => i.MastoReplyUserId,
|
||||||
|
i => i.UserId != user.Id
|
||||||
|
? i.UserId
|
||||||
|
: mastoReplyUserId));
|
||||||
|
|
||||||
|
count +=
|
||||||
await bgDb.Notes.Where(p => p.RenoteUri == uri)
|
await bgDb.Notes.Where(p => p.RenoteUri == uri)
|
||||||
.ExecuteUpdateAsync(p => p.SetProperty(i => i.RenoteId, _ => note.Id)
|
.ExecuteUpdateAsync(p => p.SetProperty(i => i.RenoteUri, _ => null)
|
||||||
.SetProperty(i => i.RenoteUri, _ => null));
|
.SetProperty(i => i.RenoteId, _ => note.Id)
|
||||||
|
.SetProperty(i => i.RenoteUserId, _ => note.UserId)
|
||||||
|
.SetProperty(i => i.RenoteUserHost, _ => note.UserHost));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url != null)
|
if (url != null)
|
||||||
{
|
{
|
||||||
|
count +=
|
||||||
await bgDb.Notes.Where(p => p.ReplyUri == url)
|
await bgDb.Notes.Where(p => p.ReplyUri == url)
|
||||||
.ExecuteUpdateAsync(p => p.SetProperty(i => i.ReplyId, _ => note.Id)
|
.ExecuteUpdateAsync(p => p.SetProperty(i => i.ReplyUri, _ => null)
|
||||||
.SetProperty(i => i.ReplyUri, _ => null));
|
.SetProperty(i => i.ReplyId, _ => note.Id)
|
||||||
|
.SetProperty(i => i.ReplyUserId, _ => note.UserId)
|
||||||
|
.SetProperty(i => i.ReplyUserHost, _ => note.UserHost)
|
||||||
|
.SetProperty(i => i.MastoReplyUserId,
|
||||||
|
i => i.UserId != user.Id
|
||||||
|
? i.UserId
|
||||||
|
: mastoReplyUserId));
|
||||||
|
count +=
|
||||||
await bgDb.Notes.Where(p => p.RenoteUri == url)
|
await bgDb.Notes.Where(p => p.RenoteUri == url)
|
||||||
.ExecuteUpdateAsync(p => p.SetProperty(i => i.RenoteId, _ => note.Id)
|
.ExecuteUpdateAsync(p => p.SetProperty(i => i.RenoteUri, _ => null)
|
||||||
.SetProperty(i => i.RenoteUri, _ => null));
|
.SetProperty(i => i.RenoteId, _ => note.Id)
|
||||||
|
.SetProperty(i => i.RenoteUserId, _ => note.UserId)
|
||||||
|
.SetProperty(i => i.RenoteUserHost, _ => note.UserHost));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
await bgDb.Notes.Where(p => p.Id == note.Id)
|
||||||
|
.ExecuteUpdateAsync(p => p.SetProperty(i => i.RepliesCount,
|
||||||
|
i => db.Notes.Count(n => n.ReplyId == i.Id))
|
||||||
|
.SetProperty(i => i.RenoteCount,
|
||||||
|
i => db.Notes.Count(n => n.RenoteId == i.Id &&
|
||||||
|
n.IsPureRenote)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue