mirror of
				https://github.com/KevinMidboe/immich.git
				synced 2025-10-29 17:40:28 +00:00 
			
		
		
		
	Optimization/fix slow backup when asset list is long. (#104)
* Handle pause/restart listening to event on_upload_success and reload asset list after navigating back from BackupControllerPage * Remove unused api endpoint
This commit is contained in:
		| @@ -115,18 +115,8 @@ export class AssetController { | ||||
|     return this.assetService.searchAsset(authUser, searchAssetDto); | ||||
|   } | ||||
|  | ||||
|   @Get('/new') | ||||
|   async getNewAssets(@GetAuthUser() authUser: AuthUserDto, @Query(ValidationPipe) query: GetNewAssetQueryDto) { | ||||
|     return await this.assetService.getNewAssets(authUser, query.latestDate); | ||||
|   } | ||||
|  | ||||
|   @Get('/all') | ||||
|   async getAllAssets(@GetAuthUser() authUser: AuthUserDto, @Query(ValidationPipe) query: GetAllAssetQueryDto) { | ||||
|     return await this.assetService.getAllAssets(authUser, query); | ||||
|   } | ||||
|  | ||||
|   @Get('/') | ||||
|   async getAllAssetsNoPagination(@GetAuthUser() authUser: AuthUserDto) { | ||||
|   async getAllAssets(@GetAuthUser() authUser: AuthUserDto) { | ||||
|     return await this.assetService.getAllAssetsNoPagination(authUser); | ||||
|   } | ||||
|  | ||||
| @@ -137,7 +127,7 @@ export class AssetController { | ||||
|  | ||||
|   @Get('/assetById/:assetId') | ||||
|   async getAssetById(@GetAuthUser() authUser: AuthUserDto, @Param('assetId') assetId) { | ||||
|     return this.assetService.getAssetById(authUser, assetId); | ||||
|     return await this.assetService.getAssetById(authUser, assetId); | ||||
|   } | ||||
|  | ||||
|   @Delete('/') | ||||
|   | ||||
| @@ -76,42 +76,6 @@ export class AssetService { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   public async getAllAssets(authUser: AuthUserDto, query: GetAllAssetQueryDto): Promise<GetAllAssetReponseDto> { | ||||
|     try { | ||||
|       const assets = await this.assetRepository | ||||
|         .createQueryBuilder('a') | ||||
|         .where('a."userId" = :userId', { userId: authUser.id }) | ||||
|         .andWhere('a."createdAt" < :lastQueryCreatedAt', { | ||||
|           lastQueryCreatedAt: query.nextPageKey || new Date().toISOString(), | ||||
|         }) | ||||
|         .orderBy('a."createdAt"::date', 'DESC') | ||||
|         .take(5000) | ||||
|         .getMany(); | ||||
|  | ||||
|       if (assets.length > 0) { | ||||
|         const data = _.groupBy(assets, (a) => new Date(a.createdAt).toISOString().slice(0, 10)); | ||||
|         const formattedData = []; | ||||
|         Object.keys(data).forEach((v) => formattedData.push({ date: v, assets: data[v] })); | ||||
|  | ||||
|         const response = new GetAllAssetReponseDto(); | ||||
|         response.count = assets.length; | ||||
|         response.data = formattedData; | ||||
|         response.nextPageKey = assets[assets.length - 1].createdAt; | ||||
|  | ||||
|         return response; | ||||
|       } else { | ||||
|         const response = new GetAllAssetReponseDto(); | ||||
|         response.count = 0; | ||||
|         response.data = []; | ||||
|         response.nextPageKey = 'null'; | ||||
|  | ||||
|         return response; | ||||
|       } | ||||
|     } catch (e) { | ||||
|       Logger.error(e, 'getAllAssets'); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   public async findOne(authUser: AuthUserDto, deviceId: string, assetId: string): Promise<AssetEntity> { | ||||
|     const rows = await this.assetRepository.query( | ||||
|       'SELECT * FROM assets a WHERE a."deviceAssetId" = $1 AND a."userId" = $2 AND a."deviceId" = $3', | ||||
| @@ -125,18 +89,6 @@ export class AssetService { | ||||
|     return rows[0] as AssetEntity; | ||||
|   } | ||||
|  | ||||
|   public async getNewAssets(authUser: AuthUserDto, latestDate: string) { | ||||
|     return await this.assetRepository.find({ | ||||
|       where: { | ||||
|         userId: authUser.id, | ||||
|         createdAt: MoreThan(latestDate), | ||||
|       }, | ||||
|       order: { | ||||
|         createdAt: 'ASC', // ASC order to add existed asset the latest group first before creating a new date group. | ||||
|       }, | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   public async getAssetById(authUser: AuthUserDto, assetId: string) { | ||||
|     return await this.assetRepository.findOne({ | ||||
|       where: { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user