From ef86a77946ed73115ce09741ee36ad71c11145a4 Mon Sep 17 00:00:00 2001 From: Michel Heusschen <59014050+michelheusschen@users.noreply.github.com> Date: Fri, 2 Jun 2023 21:04:07 +0200 Subject: [PATCH] refactor(server): remove invalid exif coordinates (#2651) --- .../1685731372040-RemoveInvalidCoordinates.ts | 16 ++++++++++++++++ .../infra/src/repositories/asset.repository.ts | 9 +++------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 server/libs/infra/src/migrations/1685731372040-RemoveInvalidCoordinates.ts diff --git a/server/libs/infra/src/migrations/1685731372040-RemoveInvalidCoordinates.ts b/server/libs/infra/src/migrations/1685731372040-RemoveInvalidCoordinates.ts new file mode 100644 index 0000000000..9a9b00a366 --- /dev/null +++ b/server/libs/infra/src/migrations/1685731372040-RemoveInvalidCoordinates.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class RemoveInvalidCoordinates1685731372040 implements MigrationInterface { + name = 'RemoveInvalidCoordinates1685731372040'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`UPDATE "exif" SET "latitude" = NULL WHERE "latitude" IN ('NaN', 'Infinity', '-Infinity')`); + await queryRunner.query( + `UPDATE "exif" SET "longitude" = NULL WHERE "longitude" IN ('NaN', 'Infinity', '-Infinity')`, + ); + } + + public async down(): Promise { + // Empty, data cannot be restored + } +} diff --git a/server/libs/infra/src/repositories/asset.repository.ts b/server/libs/infra/src/repositories/asset.repository.ts index 1c72cc1128..ec836623c4 100644 --- a/server/libs/infra/src/repositories/asset.repository.ts +++ b/server/libs/infra/src/repositories/asset.repository.ts @@ -11,7 +11,7 @@ import { } from '@app/domain'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; -import { FindOptionsRelations, FindOptionsWhere, In, IsNull, Not, Raw, Repository } from 'typeorm'; +import { FindOptionsRelations, FindOptionsWhere, In, IsNull, Not, Repository } from 'typeorm'; import { AssetEntity, AssetType } from '../entities'; import OptionalBetween from '../utils/optional-between.util'; import { paginate } from '../utils/pagination.util'; @@ -214,9 +214,6 @@ export class AssetRepository implements IAssetRepository { async getMapMarkers(ownerId: string, options: MapMarkerSearchOptions = {}): Promise { const { isFavorite, fileCreatedAfter, fileCreatedBefore } = options; - const coordinateFilter = Raw( - (column) => `${column} IS NOT NULL AND ${column} NOT IN ('NaN', 'Infinity', '-Infinity')`, - ); const assets = await this.repository.find({ select: { @@ -231,8 +228,8 @@ export class AssetRepository implements IAssetRepository { isVisible: true, isArchived: false, exifInfo: { - latitude: coordinateFilter, - longitude: coordinateFilter, + latitude: Not(IsNull()), + longitude: Not(IsNull()), }, isFavorite, fileCreatedAt: OptionalBetween(fileCreatedAfter, fileCreatedBefore),