CompileAsyncQuery: FilesSpaceUsageStatManager
This commit is contained in:
parent
80c7ee41b0
commit
6ce91c34f5
@ -126,9 +126,7 @@ public class FilesSpaceUsageStatManager : SpaceUsageStatManager, IUserSpaceUsage
|
|||||||
var trash = await _globalFolder.GetFolderTrashAsync(_daoFactory);
|
var trash = await _globalFolder.GetFolderTrashAsync(_daoFactory);
|
||||||
|
|
||||||
using var filesDbContext = _dbContextFactory.CreateDbContext();
|
using var filesDbContext = _dbContextFactory.CreateDbContext();
|
||||||
return await filesDbContext.Files
|
return await Queries.SumContentLengthAsync(filesDbContext, tenantId, userId, my, trash);
|
||||||
.Where(r => r.TenantId == tenantId && r.CreateBy == userId && (r.ParentId == my || r.ParentId == trash))
|
|
||||||
.SumAsync(r => r.ContentLength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RecalculateUserQuota(int TenantId, Guid userId)
|
public async Task RecalculateUserQuota(int TenantId, Guid userId)
|
||||||
@ -149,3 +147,12 @@ public static class FilesSpaceUsageStatExtension
|
|||||||
services.ServiceCollection.AddBaseDbContextPool<FilesDbContext>();
|
services.ServiceCollection.AddBaseDbContextPool<FilesDbContext>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file static class Queries
|
||||||
|
{
|
||||||
|
public static readonly Func<FilesDbContext, int, Guid, int, int, Task<long>> SumContentLengthAsync = Microsoft.EntityFrameworkCore.EF.CompileAsyncQuery(
|
||||||
|
(FilesDbContext ctx, int tenantId, Guid userId, int my, int trash) =>
|
||||||
|
ctx.Files
|
||||||
|
.Where(r => r.TenantId == tenantId && r.CreateBy == userId && (r.ParentId == my || r.ParentId == trash))
|
||||||
|
.Sum(r => r.ContentLength));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user