Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): include partner assets in random endpoint #12599

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/src/interfaces/asset.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export interface IAssetRepository {
libraryId?: string,
withDeleted?: boolean,
): Paginated<AssetEntity>;
getRandom(userId: string, count: number): Promise<AssetEntity[]>;
getRandom(userIds: string[], count: number): Promise<AssetEntity[]>;
getFirstAssetForAlbumId(albumId: string): Promise<AssetEntity | null>;
getLastUpdatedAssetForAlbumId(albumId: string): Promise<AssetEntity | null>;
getExternalLibraryAssetPaths(pagination: PaginationOptions, libraryId: string): Paginated<AssetPathEntity>;
Expand Down
11 changes: 3 additions & 8 deletions server/src/repositories/asset.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,9 @@ export class AssetRepository implements IAssetRepository {
return result;
}

@GenerateSql({ params: [DummyValue.UUID, DummyValue.NUMBER] })
getRandom(ownerId: string, count: number): Promise<AssetEntity[]> {
const builder = this.getBuilder({
userIds: [ownerId],
exifInfo: true,
});

return builder.orderBy('RANDOM()').limit(count).getMany();
@GenerateSql({ params: [[DummyValue.UUID], DummyValue.NUMBER] })
getRandom(userIds: string[], count: number): Promise<AssetEntity[]> {
return this.getBuilder({ userIds, exifInfo: true }).orderBy('RANDOM()').limit(count).getMany();
}

@GenerateSql({ params: [{ size: TimeBucketSize.MONTH }] })
Expand Down
7 changes: 6 additions & 1 deletion server/src/services/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ export class AssetService {
}

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 }));
}

Expand Down
Loading