Skip to content

Commit

Permalink
memory includes assets in shared albums
Browse files Browse the repository at this point in the history
  • Loading branch information
ExceptionsOccur committed Jan 16, 2025
1 parent ab855cb commit 208e179
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/src/interfaces/asset.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export interface IAssetRepository {
create(asset: Insertable<Assets>): Promise<AssetEntity>;
getByIds(ids: string[], relations?: GetByIdsRelations): Promise<AssetEntity[]>;
getByIdsWithAllRelations(ids: string[]): Promise<AssetEntity[]>;
getByDayOfYear(ownerIds: string[], monthDay: MonthDay): Promise<DayOfYearAssets[]>;
getByDayOfYear(ownerIds: string[], albumIds: string[], monthDay: MonthDay): Promise<DayOfYearAssets[]>;
getByChecksum(options: AssetGetByChecksumOptions): Promise<AssetEntity | undefined>;
getByChecksums(userId: string, checksums: Buffer[]): Promise<AssetEntity[]>;
getUploadAssetIdByChecksum(ownerId: string, checksum: Buffer): Promise<string | undefined>;
Expand Down
21 changes: 19 additions & 2 deletions server/src/repositories/asset.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class AssetRepository implements IAssetRepository {
}

@GenerateSql({ params: [DummyValue.UUID, { day: 1, month: 1 }] })
getByDayOfYear(ownerIds: string[], { day, month }: MonthDay): Promise<DayOfYearAssets[]> {
getByDayOfYear(ownerIds: string[], albumIds: string[], { day, month }: MonthDay): Promise<DayOfYearAssets[]> {
return this.db
.with('res', (qb) =>
qb
Expand All @@ -110,7 +110,20 @@ export class AssetRepository implements IAssetRepository {
.innerJoin('asset_job_status', 'assets.id', 'asset_job_status.assetId')
.where('asset_job_status.previewAt', 'is not', null)
.where(sql`(assets."localDateTime" at time zone 'UTC')::date`, '=', sql`today.date`)
.where('assets.ownerId', '=', anyUuid(ownerIds))
.where(({eb, and, or}) => or([
// assets in share albums and not ownerIds own
and([
eb.exists((qb)=>
qb
.selectFrom('albums_assets_assets')
.whereRef('albums_assets_assets.assetsId', '=', 'assets.id')
.where('albums_assets_assets.albumsId', '=', anyUuid(albumIds))
),
eb('assets.ownerId', '!=', anyUuid(ownerIds))
]),
// ownerIds own
eb('assets.ownerId', '=', anyUuid(ownerIds))
]))
.where('assets.isVisible', '=', true)
.where('assets.isArchived', '=', false)
.where((eb) =>
Expand All @@ -122,6 +135,10 @@ export class AssetRepository implements IAssetRepository {
),
)
.where('assets.deletedAt', 'is', null)
// TODO optimize the query to avoid performance issues caused by a large amount of data
// If the same photo is uploaded twice by user A and user B respectively,
// when the photo appears in the sharing, the result will show duplicates
.distinctOn('assets.checksum')
.limit(10)
.as('a'),
(join) => join.onTrue(),
Expand Down
3 changes: 2 additions & 1 deletion server/src/services/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ export class AssetService extends BaseService {
timelineEnabled: true,
});
const userIds = [auth.user.id, ...partnerIds];
const shareAlbums = await this.albumRepository.getShared(auth.user.id);

const groups = await this.assetRepository.getByDayOfYear(userIds, dto);
const groups = await this.assetRepository.getByDayOfYear(userIds, shareAlbums.length > 0 ? shareAlbums.map(el=>el.id) : [], dto);
return groups.map(({ yearsAgo, assets }) => ({
yearsAgo,
// TODO move this to clients
Expand Down

0 comments on commit 208e179

Please sign in to comment.