🗑️ Clean up the cloud file table unused fields
This commit is contained in:
@@ -42,9 +42,11 @@ public class UsageService(AppDatabase db)
|
||||
PoolName = p.Name,
|
||||
UsageBytes = fileQuery
|
||||
.Where(f => f.PoolId == p.Id)
|
||||
.Include(f => f.Object)
|
||||
.Sum(f => f.Size),
|
||||
Cost = fileQuery
|
||||
.Where(f => f.PoolId == p.Id)
|
||||
.Include(f => f.Object)
|
||||
.Sum(f => f.Size) / 1024.0 / 1024.0 *
|
||||
(p.BillingConfig.CostMultiplier ?? 1.0),
|
||||
FileCount = fileQuery
|
||||
@@ -80,6 +82,7 @@ public class UsageService(AppDatabase db)
|
||||
.AsQueryable();
|
||||
|
||||
var usageBytes = await fileQuery
|
||||
.Include(f => f.Object)
|
||||
.SumAsync(f => f.Size);
|
||||
|
||||
var fileCount = await fileQuery
|
||||
@@ -106,6 +109,7 @@ public class UsageService(AppDatabase db)
|
||||
.Where(f => f.PoolId.HasValue)
|
||||
.Where(f => !f.IsMarkedRecycle)
|
||||
.Include(f => f.Pool)
|
||||
.Include(f => f.Object)
|
||||
.Where(f => !f.ExpiredAt.HasValue || f.ExpiredAt > now)
|
||||
.Select(f => new
|
||||
{
|
||||
|
||||
@@ -216,6 +216,7 @@ public class FileIndexController(
|
||||
&& f.IsMarkedRecycle == recycled
|
||||
&& !db.FileIndexes.Any(fi => fi.FileId == f.Id && fi.AccountId == accountId)
|
||||
)
|
||||
.Include(f => f.Object)
|
||||
.AsQueryable();
|
||||
|
||||
// Apply sorting
|
||||
|
||||
@@ -167,6 +167,7 @@ public class FileIndexService(AppDatabase db)
|
||||
return await db.FileIndexes
|
||||
.Where(fi => fi.AccountId == accountId)
|
||||
.Include(fi => fi.File)
|
||||
.ThenInclude(f => f.Object)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
|
||||
@@ -314,9 +314,12 @@ public class BroadcastEventHandler(
|
||||
await scopedDb.Files.Where(f => f.Id == fileId).ExecuteUpdateAsync(setter => setter
|
||||
.SetProperty(f => f.UploadedAt, now)
|
||||
.SetProperty(f => f.PoolId, destPool)
|
||||
.SetProperty(f => f.MimeType, newMimeType)
|
||||
.SetProperty(f => f.HasCompression, hasCompression)
|
||||
.SetProperty(f => f.HasThumbnail, hasThumbnail)
|
||||
);
|
||||
|
||||
await scopedDb.FileObjects.Where(fo => fo.Id == fileId).ExecuteUpdateAsync(setter => setter
|
||||
.SetProperty(fo => fo.MimeType, newMimeType)
|
||||
.SetProperty(fo => fo.HasCompression, hasCompression)
|
||||
.SetProperty(fo => fo.HasThumbnail, hasThumbnail)
|
||||
);
|
||||
|
||||
// Only delete temp file after successful upload and db update
|
||||
|
||||
@@ -303,6 +303,7 @@ public class FileController(
|
||||
.Where(e => e.IsMarkedRecycle == recycled)
|
||||
.Where(e => e.AccountId == accountId)
|
||||
.Include(e => e.Pool)
|
||||
.Include(e => e.Object)
|
||||
.AsQueryable();
|
||||
|
||||
if (pool.HasValue) filesQuery = filesQuery.Where(e => e.PoolId == pool);
|
||||
|
||||
@@ -64,7 +64,10 @@ public class FileUploadController(
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
|
||||
// Check if a file with the same hash already exists
|
||||
var existingFile = await db.Files.FirstOrDefaultAsync(f => f.Hash == request.Hash);
|
||||
var existingFile = await db.Files
|
||||
.Include(f => f.Object)
|
||||
.Where(f => f.Object != null && f.Object.Hash == request.Hash)
|
||||
.FirstOrDefaultAsync();
|
||||
if (existingFile != null)
|
||||
{
|
||||
// Create the file index if a path is provided, even for existing files
|
||||
|
||||
Reference in New Issue
Block a user