mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
chore: remove unused types and code (#17999)
This commit is contained in:
parent
526c02297c
commit
1fde02ee1e
@ -46,7 +46,7 @@ export class SearchController {
|
|||||||
@Get('explore')
|
@Get('explore')
|
||||||
@Authenticated()
|
@Authenticated()
|
||||||
getExploreData(@Auth() auth: AuthDto): Promise<SearchExploreResponseDto[]> {
|
getExploreData(@Auth() auth: AuthDto): Promise<SearchExploreResponseDto[]> {
|
||||||
return this.service.getExploreData(auth) as Promise<SearchExploreResponseDto[]>;
|
return this.service.getExploreData(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('person')
|
@Get('person')
|
||||||
|
@ -7,7 +7,6 @@ import { AssetFiles, AssetJobStatus, Assets, DB, Exif } from 'src/db';
|
|||||||
import { Chunked, ChunkedArray, DummyValue, GenerateSql } from 'src/decorators';
|
import { Chunked, ChunkedArray, DummyValue, GenerateSql } from 'src/decorators';
|
||||||
import { MapAsset } from 'src/dtos/asset-response.dto';
|
import { MapAsset } from 'src/dtos/asset-response.dto';
|
||||||
import { AssetFileType, AssetOrder, AssetStatus, AssetType } from 'src/enum';
|
import { AssetFileType, AssetOrder, AssetStatus, AssetType } from 'src/enum';
|
||||||
import { SearchExploreItem, SearchExploreItemSet } from 'src/repositories/search.repository';
|
|
||||||
import {
|
import {
|
||||||
anyUuid,
|
anyUuid,
|
||||||
asUuid,
|
asUuid,
|
||||||
@ -687,10 +686,7 @@ export class AssetRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [DummyValue.UUID, { minAssetsPerField: 5, maxFields: 12 }] })
|
@GenerateSql({ params: [DummyValue.UUID, { minAssetsPerField: 5, maxFields: 12 }] })
|
||||||
async getAssetIdByCity(
|
async getAssetIdByCity(ownerId: string, { minAssetsPerField, maxFields }: AssetExploreFieldOptions) {
|
||||||
ownerId: string,
|
|
||||||
{ minAssetsPerField, maxFields }: AssetExploreFieldOptions,
|
|
||||||
): Promise<SearchExploreItem<string>> {
|
|
||||||
const items = await this.db
|
const items = await this.db
|
||||||
.with('cities', (qb) =>
|
.with('cities', (qb) =>
|
||||||
qb
|
qb
|
||||||
@ -705,6 +701,7 @@ export class AssetRepository {
|
|||||||
.innerJoin('cities', 'exif.city', 'cities.city')
|
.innerJoin('cities', 'exif.city', 'cities.city')
|
||||||
.distinctOn('exif.city')
|
.distinctOn('exif.city')
|
||||||
.select(['assetId as data', 'exif.city as value'])
|
.select(['assetId as data', 'exif.city as value'])
|
||||||
|
.$narrowType<{ value: NotNull }>()
|
||||||
.where('ownerId', '=', asUuid(ownerId))
|
.where('ownerId', '=', asUuid(ownerId))
|
||||||
.where('isVisible', '=', true)
|
.where('isVisible', '=', true)
|
||||||
.where('isArchived', '=', false)
|
.where('isArchived', '=', false)
|
||||||
@ -713,7 +710,7 @@ export class AssetRepository {
|
|||||||
.limit(maxFields)
|
.limit(maxFields)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
return { fieldName: 'exifInfo.city', items: items as SearchExploreItemSet<string> };
|
return { fieldName: 'exifInfo.city', items };
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({
|
@GenerateSql({
|
||||||
|
@ -6,7 +6,7 @@ import { AssetFaces, DB, FaceSearch, Person } from 'src/db';
|
|||||||
import { ChunkedArray, DummyValue, GenerateSql } from 'src/decorators';
|
import { ChunkedArray, DummyValue, GenerateSql } from 'src/decorators';
|
||||||
import { AssetFileType, SourceType } from 'src/enum';
|
import { AssetFileType, SourceType } from 'src/enum';
|
||||||
import { removeUndefinedKeys } from 'src/utils/database';
|
import { removeUndefinedKeys } from 'src/utils/database';
|
||||||
import { PaginationOptions } from 'src/utils/pagination';
|
import { paginationHelper, PaginationOptions } from 'src/utils/pagination';
|
||||||
|
|
||||||
export interface PersonSearchOptions {
|
export interface PersonSearchOptions {
|
||||||
minimumFaceCount: number;
|
minimumFaceCount: number;
|
||||||
@ -200,11 +200,7 @@ export class PersonRepository {
|
|||||||
.limit(pagination.take + 1)
|
.limit(pagination.take + 1)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
if (items.length > pagination.take) {
|
return paginationHelper(items, pagination.take);
|
||||||
return { items: items.slice(0, -1), hasNextPage: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
return { items, hasNextPage: false };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql()
|
@GenerateSql()
|
||||||
|
@ -8,41 +8,10 @@ import { MapAsset } from 'src/dtos/asset-response.dto';
|
|||||||
import { AssetStatus, AssetType } from 'src/enum';
|
import { AssetStatus, AssetType } from 'src/enum';
|
||||||
import { ConfigRepository } from 'src/repositories/config.repository';
|
import { ConfigRepository } from 'src/repositories/config.repository';
|
||||||
import { anyUuid, asUuid, searchAssetBuilder, vectorIndexQuery } from 'src/utils/database';
|
import { anyUuid, asUuid, searchAssetBuilder, vectorIndexQuery } from 'src/utils/database';
|
||||||
|
import { paginationHelper } from 'src/utils/pagination';
|
||||||
import { isValidInteger } from 'src/validation';
|
import { isValidInteger } from 'src/validation';
|
||||||
|
|
||||||
export interface SearchResult<T> {
|
export interface SearchAssetIdOptions {
|
||||||
/** total matches */
|
|
||||||
total: number;
|
|
||||||
/** collection size */
|
|
||||||
count: number;
|
|
||||||
/** current page */
|
|
||||||
page: number;
|
|
||||||
/** items for page */
|
|
||||||
items: T[];
|
|
||||||
/** score */
|
|
||||||
distances: number[];
|
|
||||||
facets: SearchFacet[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SearchFacet {
|
|
||||||
fieldName: string;
|
|
||||||
counts: Array<{
|
|
||||||
count: number;
|
|
||||||
value: string;
|
|
||||||
}>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SearchExploreItemSet<T> = Array<{
|
|
||||||
value: string;
|
|
||||||
data: T;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export interface SearchExploreItem<T> {
|
|
||||||
fieldName: string;
|
|
||||||
items: SearchExploreItemSet<T>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SearchAssetIDOptions {
|
|
||||||
checksum?: Buffer;
|
checksum?: Buffer;
|
||||||
deviceAssetId?: string;
|
deviceAssetId?: string;
|
||||||
id?: string;
|
id?: string;
|
||||||
@ -54,7 +23,7 @@ export interface SearchUserIdOptions {
|
|||||||
userIds?: string[];
|
userIds?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SearchIdOptions = SearchAssetIDOptions & SearchUserIdOptions;
|
export type SearchIdOptions = SearchAssetIdOptions & SearchUserIdOptions;
|
||||||
|
|
||||||
export interface SearchStatusOptions {
|
export interface SearchStatusOptions {
|
||||||
isArchived?: boolean;
|
isArchived?: boolean;
|
||||||
@ -144,8 +113,6 @@ type BaseAssetSearchOptions = SearchDateOptions &
|
|||||||
|
|
||||||
export type AssetSearchOptions = BaseAssetSearchOptions & SearchRelationOptions;
|
export type AssetSearchOptions = BaseAssetSearchOptions & SearchRelationOptions;
|
||||||
|
|
||||||
export type AssetSearchOneToOneRelationOptions = BaseAssetSearchOptions & SearchOneToOneRelationOptions;
|
|
||||||
|
|
||||||
export type AssetSearchBuilderOptions = Omit<AssetSearchOptions, 'orderDirection'>;
|
export type AssetSearchBuilderOptions = Omit<AssetSearchOptions, 'orderDirection'>;
|
||||||
|
|
||||||
export type SmartSearchOptions = SearchDateOptions &
|
export type SmartSearchOptions = SearchDateOptions &
|
||||||
@ -226,9 +193,8 @@ export class SearchRepository {
|
|||||||
.limit(pagination.size + 1)
|
.limit(pagination.size + 1)
|
||||||
.offset((pagination.page - 1) * pagination.size)
|
.offset((pagination.page - 1) * pagination.size)
|
||||||
.execute();
|
.execute();
|
||||||
const hasNextPage = items.length > pagination.size;
|
|
||||||
items.splice(pagination.size);
|
return paginationHelper(items, pagination.size);
|
||||||
return { items, hasNextPage };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({
|
@GenerateSql({
|
||||||
@ -283,9 +249,7 @@ export class SearchRepository {
|
|||||||
.offset((pagination.page - 1) * pagination.size)
|
.offset((pagination.page - 1) * pagination.size)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
const hasNextPage = items.length > pagination.size;
|
return paginationHelper(items, pagination.size);
|
||||||
items.splice(pagination.size);
|
|
||||||
return { items, hasNextPage };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({
|
@GenerateSql({
|
||||||
|
@ -15,7 +15,6 @@ import {
|
|||||||
SmartSearchDto,
|
SmartSearchDto,
|
||||||
} from 'src/dtos/search.dto';
|
} from 'src/dtos/search.dto';
|
||||||
import { AssetOrder } from 'src/enum';
|
import { AssetOrder } from 'src/enum';
|
||||||
import { SearchExploreItem } from 'src/repositories/search.repository';
|
|
||||||
import { BaseService } from 'src/services/base.service';
|
import { BaseService } from 'src/services/base.service';
|
||||||
import { getMyPartnerIds } from 'src/utils/asset.util';
|
import { getMyPartnerIds } from 'src/utils/asset.util';
|
||||||
import { isSmartSearchEnabled } from 'src/utils/misc';
|
import { isSmartSearchEnabled } from 'src/utils/misc';
|
||||||
@ -32,7 +31,7 @@ export class SearchService extends BaseService {
|
|||||||
return places.map((place) => mapPlaces(place));
|
return places.map((place) => mapPlaces(place));
|
||||||
}
|
}
|
||||||
|
|
||||||
async getExploreData(auth: AuthDto): Promise<SearchExploreItem<AssetResponseDto>[]> {
|
async getExploreData(auth: AuthDto) {
|
||||||
const options = { maxFields: 12, minAssetsPerField: 5 };
|
const options = { maxFields: 12, minAssetsPerField: 5 };
|
||||||
const cities = await this.assetRepository.getAssetIdByCity(auth.user.id, options);
|
const cities = await this.assetRepository.getAssetIdByCity(auth.user.id, options);
|
||||||
const assets = await this.assetRepository.getByIdsWithAllRelationsButStacks(cities.items.map(({ data }) => data));
|
const assets = await this.assetRepository.getByIdsWithAllRelationsButStacks(cities.items.map(({ data }) => data));
|
||||||
|
@ -8,22 +8,6 @@ export interface PaginationResult<T> {
|
|||||||
hasNextPage: boolean;
|
hasNextPage: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Paginated<T> = Promise<PaginationResult<T>>;
|
|
||||||
|
|
||||||
/** @deprecated use `this.db. ... .stream()` instead */
|
|
||||||
export async function* usePagination<T>(
|
|
||||||
pageSize: number,
|
|
||||||
getNextPage: (pagination: PaginationOptions) => PaginationResult<T> | Paginated<T>,
|
|
||||||
) {
|
|
||||||
let hasNextPage = true;
|
|
||||||
|
|
||||||
for (let skip = 0; hasNextPage; skip += pageSize) {
|
|
||||||
const result = await getNextPage({ take: pageSize, skip });
|
|
||||||
hasNextPage = result.hasNextPage;
|
|
||||||
yield result.items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function paginationHelper<Entity extends object>(items: Entity[], take: number): PaginationResult<Entity> {
|
export function paginationHelper<Entity extends object>(items: Entity[], take: number): PaginationResult<Entity> {
|
||||||
const hasNextPage = items.length > take;
|
const hasNextPage = items.length > take;
|
||||||
items.splice(take);
|
items.splice(take);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user