From b21d9691e5040e3daecacbf7af5104c4ad71bf2d Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sat, 19 Oct 2024 00:21:01 +0200 Subject: [PATCH] [backend/drive] Improve media fixup algorithm --- .../Core/Services/StorageMaintenanceService.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Iceshrimp.Backend/Core/Services/StorageMaintenanceService.cs b/Iceshrimp.Backend/Core/Services/StorageMaintenanceService.cs index 2c2c92f2..8ff9e9f3 100644 --- a/Iceshrimp.Backend/Core/Services/StorageMaintenanceService.cs +++ b/Iceshrimp.Backend/Core/Services/StorageMaintenanceService.cs @@ -179,6 +179,10 @@ public class StorageMaintenanceService( } await driveSvc.ExpireFile(file); + await db.Users.Where(p => p.AvatarId == file.Id) + .ExecuteUpdateAsync(p => p.SetProperty(u => u.AvatarUrl, file.Uri)); + await db.Users.Where(p => p.BannerId == file.Id) + .ExecuteUpdateAsync(p => p.SetProperty(u => u.BannerUrl, file.Uri)); continue; } @@ -193,7 +197,6 @@ public class StorageMaintenanceService( file.ThumbnailAccessKey = null; file.ThumbnailUrl = null; file.ThumbnailMimeType = null; - await db.SaveChangesAsync(); } } @@ -209,9 +212,16 @@ public class StorageMaintenanceService( file.PublicAccessKey = null; file.PublicUrl = null; file.PublicMimeType = null; - await db.SaveChangesAsync(); } } + + if (dryRun) continue; + + await db.SaveChangesAsync(); + await db.Users.Where(p => p.AvatarId == file.Id) + .ExecuteUpdateAsync(p => p.SetProperty(u => u.AvatarUrl, file.AccessUrl)); + await db.Users.Where(p => p.BannerId == file.Id) + .ExecuteUpdateAsync(p => p.SetProperty(u => u.BannerUrl, file.AccessUrl)); } if (dryRun)