mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-04 03:27:09 -05:00 
			
		
		
		
	fix(server): include partner assets in random endpoint (#12599)
This commit is contained in:
		
							parent
							
								
									d03e97f650
								
							
						
					
					
						commit
						7b737786b3
					
				@ -175,7 +175,7 @@ export interface IAssetRepository {
 | 
				
			|||||||
    libraryId?: string,
 | 
					    libraryId?: string,
 | 
				
			||||||
    withDeleted?: boolean,
 | 
					    withDeleted?: boolean,
 | 
				
			||||||
  ): Paginated<AssetEntity>;
 | 
					  ): Paginated<AssetEntity>;
 | 
				
			||||||
  getRandom(userId: string, count: number): Promise<AssetEntity[]>;
 | 
					  getRandom(userIds: string[], count: number): Promise<AssetEntity[]>;
 | 
				
			||||||
  getFirstAssetForAlbumId(albumId: string): Promise<AssetEntity | null>;
 | 
					  getFirstAssetForAlbumId(albumId: string): Promise<AssetEntity | null>;
 | 
				
			||||||
  getLastUpdatedAssetForAlbumId(albumId: string): Promise<AssetEntity | null>;
 | 
					  getLastUpdatedAssetForAlbumId(albumId: string): Promise<AssetEntity | null>;
 | 
				
			||||||
  getExternalLibraryAssetPaths(pagination: PaginationOptions, libraryId: string): Paginated<AssetPathEntity>;
 | 
					  getExternalLibraryAssetPaths(pagination: PaginationOptions, libraryId: string): Paginated<AssetPathEntity>;
 | 
				
			||||||
 | 
				
			|||||||
@ -623,14 +623,9 @@ export class AssetRepository implements IAssetRepository {
 | 
				
			|||||||
    return result;
 | 
					    return result;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @GenerateSql({ params: [DummyValue.UUID, DummyValue.NUMBER] })
 | 
					  @GenerateSql({ params: [[DummyValue.UUID], DummyValue.NUMBER] })
 | 
				
			||||||
  getRandom(ownerId: string, count: number): Promise<AssetEntity[]> {
 | 
					  getRandom(userIds: string[], count: number): Promise<AssetEntity[]> {
 | 
				
			||||||
    const builder = this.getBuilder({
 | 
					    return this.getBuilder({ userIds, exifInfo: true }).orderBy('RANDOM()').limit(count).getMany();
 | 
				
			||||||
      userIds: [ownerId],
 | 
					 | 
				
			||||||
      exifInfo: true,
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return builder.orderBy('RANDOM()').limit(count).getMany();
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @GenerateSql({ params: [{ size: TimeBucketSize.MONTH }] })
 | 
					  @GenerateSql({ params: [{ size: TimeBucketSize.MONTH }] })
 | 
				
			||||||
 | 
				
			|||||||
@ -98,7 +98,12 @@ export class AssetService {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async getRandom(auth: AuthDto, count: number): Promise<AssetResponseDto[]> {
 | 
					  async getRandom(auth: AuthDto, count: number): Promise<AssetResponseDto[]> {
 | 
				
			||||||
    const assets = await this.assetRepository.getRandom(auth.user.id, count);
 | 
					    const partnerIds = await getMyPartnerIds({
 | 
				
			||||||
 | 
					      userId: auth.user.id,
 | 
				
			||||||
 | 
					      repository: this.partnerRepository,
 | 
				
			||||||
 | 
					      timelineEnabled: true,
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    const assets = await this.assetRepository.getRandom([auth.user.id, ...partnerIds], count);
 | 
				
			||||||
    return assets.map((a) => mapAsset(a, { auth }));
 | 
					    return assets.map((a) => mapAsset(a, { auth }));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user