chore(web): quota enhancement (#6371)
* chore(web): quota enhancement * show quota in user table * update quota for single user ioption * Add a note how to set unlimited storage * fixed deletion doesn't update quota * refactor relation * fixed test * re-refactor * update sql * fix e2e test * Update server/src/domain/user/user.service.ts Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> * revert e2e test --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
@@ -363,16 +363,6 @@ export class AssetRepository implements IAssetRepository {
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
getById(id: string, relations: FindOptionsRelations<AssetEntity>): Promise<AssetEntity | null> {
|
||||
if (!relations) {
|
||||
relations = {
|
||||
faces: {
|
||||
person: true,
|
||||
},
|
||||
library: true,
|
||||
stack: true,
|
||||
};
|
||||
}
|
||||
|
||||
return this.repository.findOne({
|
||||
where: { id },
|
||||
relations,
|
||||
|
||||
@@ -115,7 +115,8 @@ export class UserRepository implements IUserRepository {
|
||||
await this.userRepository.increment({ id }, 'quotaUsageInBytes', delta);
|
||||
}
|
||||
|
||||
async syncUsage() {
|
||||
@GenerateSql({ params: [DummyValue.UUID] })
|
||||
async syncUsage(id?: string) {
|
||||
const subQuery = this.assetRepository
|
||||
.createQueryBuilder('assets')
|
||||
.select('COALESCE(SUM(exif."fileSizeInByte"), 0)')
|
||||
@@ -123,12 +124,17 @@ export class UserRepository implements IUserRepository {
|
||||
.where('assets.ownerId = users.id')
|
||||
.withDeleted();
|
||||
|
||||
await this.userRepository
|
||||
const query = this.userRepository
|
||||
.createQueryBuilder('users')
|
||||
.leftJoin('users.assets', 'assets')
|
||||
.update()
|
||||
.set({ quotaUsageInBytes: () => `(${subQuery.getQuery()})` })
|
||||
.execute();
|
||||
.set({ quotaUsageInBytes: () => `(${subQuery.getQuery()})` });
|
||||
|
||||
if (id) {
|
||||
query.where('users.id = :id', { id });
|
||||
}
|
||||
|
||||
await query.execute();
|
||||
}
|
||||
|
||||
private async save(user: Partial<UserEntity>) {
|
||||
|
||||
Reference in New Issue
Block a user