mirror of
https://github.com/immich-app/immich.git
synced 2025-03-11 02:23:09 -05:00
fix(server): assets in multiple albums duplicated in map view (#16245)
This commit is contained in:
parent
3925445de8
commit
616905211d
3 changed files with 23 additions and 29 deletions
|
@ -13,10 +13,19 @@ from
|
|||
inner join "exif" on "assets"."id" = "exif"."assetId"
|
||||
and "exif"."latitude" is not null
|
||||
and "exif"."longitude" is not null
|
||||
left join "albums_assets_assets" on "assets"."id" = "albums_assets_assets"."assetsId"
|
||||
where
|
||||
"isVisible" = $1
|
||||
and "deletedAt" is null
|
||||
and "ownerId" in ($2)
|
||||
and (
|
||||
"ownerId" in ($2)
|
||||
or exists (
|
||||
select
|
||||
from
|
||||
"albums_assets_assets"
|
||||
where
|
||||
"assets"."id" = "albums_assets_assets"."assetsId"
|
||||
and "albums_assets_assets"."albumsId" in ($3)
|
||||
)
|
||||
)
|
||||
order by
|
||||
"fileCreatedAt" desc
|
||||
|
|
|
@ -23,7 +23,6 @@ import {
|
|||
withTags,
|
||||
} from 'src/entities/asset.entity';
|
||||
import { AssetFileType, AssetOrder, AssetStatus, AssetType } from 'src/enum';
|
||||
import { MapMarker, MapMarkerSearchOptions } from 'src/repositories/map.repository';
|
||||
import { AssetSearchOptions, SearchExploreItem, SearchExploreItemSet } from 'src/repositories/search.repository';
|
||||
import { anyUuid, asUuid, mapUpsertColumns } from 'src/utils/database';
|
||||
import { Paginated, PaginationOptions, paginationHelper } from 'src/utils/pagination';
|
||||
|
@ -639,26 +638,6 @@ export class AssetRepository {
|
|||
.executeTakeFirst() as Promise<AssetEntity | undefined>;
|
||||
}
|
||||
|
||||
private getMapMarkers(ownerIds: string[], options: MapMarkerSearchOptions = {}): Promise<MapMarker[]> {
|
||||
const { isArchived, isFavorite, fileCreatedAfter, fileCreatedBefore } = options;
|
||||
|
||||
return this.db
|
||||
.selectFrom('assets')
|
||||
.leftJoin('exif', 'assets.id', 'exif.assetId')
|
||||
.select(['id', 'latitude as lat', 'longitude as lon', 'city', 'state', 'country'])
|
||||
.where('ownerId', '=', anyUuid(ownerIds))
|
||||
.where('latitude', 'is not', null)
|
||||
.where('longitude', 'is not', null)
|
||||
.where('isVisible', '=', true)
|
||||
.where('deletedAt', 'is', null)
|
||||
.$if(!!isArchived, (qb) => qb.where('isArchived', '=', isArchived!))
|
||||
.$if(!!isFavorite, (qb) => qb.where('isFavorite', '=', isFavorite!))
|
||||
.$if(!!fileCreatedAfter, (qb) => qb.where('fileCreatedAt', '>=', fileCreatedAfter!))
|
||||
.$if(!!fileCreatedBefore, (qb) => qb.where('fileCreatedAt', '<=', fileCreatedBefore!))
|
||||
.orderBy('fileCreatedAt', 'desc')
|
||||
.execute() as Promise<MapMarker[]>;
|
||||
}
|
||||
|
||||
getStatistics(ownerId: string, { isArchived, isFavorite, isTrashed }: AssetStatsOptions): Promise<AssetStats> {
|
||||
return this.db
|
||||
.selectFrom('assets')
|
||||
|
|
|
@ -76,7 +76,7 @@ export class MapRepository {
|
|||
this.logger.log('Geodata import completed');
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [[DummyValue.UUID], []] })
|
||||
@GenerateSql({ params: [[DummyValue.UUID], [DummyValue.UUID]] })
|
||||
getMapMarkers(ownerIds: string[], albumIds: string[], options: MapMarkerSearchOptions = {}) {
|
||||
const { isArchived, isFavorite, fileCreatedAfter, fileCreatedBefore } = options;
|
||||
|
||||
|
@ -89,25 +89,31 @@ export class MapRepository {
|
|||
.on('exif.longitude', 'is not', null),
|
||||
)
|
||||
.select(['id', 'exif.latitude as lat', 'exif.longitude as lon', 'exif.city', 'exif.state', 'exif.country'])
|
||||
.leftJoin('albums_assets_assets', (join) => join.onRef('assets.id', '=', 'albums_assets_assets.assetsId'))
|
||||
.where('isVisible', '=', true)
|
||||
.$if(isArchived !== undefined, (q) => q.where('isArchived', '=', isArchived!))
|
||||
.$if(isFavorite !== undefined, (q) => q.where('isFavorite', '=', isFavorite!))
|
||||
.$if(fileCreatedAfter !== undefined, (q) => q.where('fileCreatedAt', '>=', fileCreatedAfter!))
|
||||
.$if(fileCreatedBefore !== undefined, (q) => q.where('fileCreatedAt', '<=', fileCreatedBefore!))
|
||||
.where('deletedAt', 'is', null)
|
||||
.where((builder) => {
|
||||
.where((eb) => {
|
||||
const expression: Expression<SqlBool>[] = [];
|
||||
|
||||
if (ownerIds.length > 0) {
|
||||
expression.push(builder('ownerId', 'in', ownerIds));
|
||||
expression.push(eb('ownerId', 'in', ownerIds));
|
||||
}
|
||||
|
||||
if (albumIds.length > 0) {
|
||||
expression.push(builder('albums_assets_assets.albumsId', 'in', albumIds));
|
||||
expression.push(
|
||||
eb.exists((eb) =>
|
||||
eb
|
||||
.selectFrom('albums_assets_assets')
|
||||
.whereRef('assets.id', '=', 'albums_assets_assets.assetsId')
|
||||
.where('albums_assets_assets.albumsId', 'in', albumIds),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return builder.or(expression);
|
||||
return eb.or(expression);
|
||||
})
|
||||
.orderBy('fileCreatedAt', 'desc')
|
||||
.execute() as Promise<MapMarker[]>;
|
||||
|
|
Loading…
Add table
Reference in a new issue