🐛 Fixes bugs

This commit is contained in:
LittleSheep 2025-06-02 22:05:38 +08:00
parent 2be92d503e
commit b25b08b5c5

View File

@ -33,7 +33,6 @@ public class FileReferenceMigrationService(AppDatabase db)
private async Task ScanPosts() private async Task ScanPosts()
{ {
var posts = await db.Posts var posts = await db.Posts
.Include(p => p.OutdatedAttachments)
.ToListAsync(); .ToListAsync();
var attachmentsId = posts.SelectMany(p => p.Attachments.Select(a => a.Id)).ToList(); var attachmentsId = posts.SelectMany(p => p.Attachments.Select(a => a.Id)).ToList();
@ -56,23 +55,7 @@ public class FileReferenceMigrationService(AppDatabase db)
}).Where(x => x != null).Select(x => x!) }).Where(x => x != null).Select(x => x!)
).ToList(); ).ToList();
foreach (var post in posts)
{
var updatedAttachments = new List<CloudFileReferenceObject>();
foreach (var attachment in post.OutdatedAttachments)
{
if (await db.Files.AnyAsync(f => f.Id == attachment.Id))
updatedAttachments.Add(attachment.ToReferenceObject());
else
updatedAttachments.Add(attachment.ToReferenceObject());
}
post.Attachments = updatedAttachments;
db.Posts.Update(post);
}
await db.BulkInsertAsync(fileReferences); await db.BulkInsertAsync(fileReferences);
await db.SaveChangesAsync();
} }
private async Task ScanMessages() private async Task ScanMessages()