mirror of
https://github.com/immich-app/immich.git
synced 2024-12-25 10:43:13 +02:00
fix: reload assets from typesense results (#2615)
* fix: reload assets from typesense results * chore: coverage
This commit is contained in:
parent
6538e599dd
commit
2dfd56b49b
@ -106,9 +106,22 @@ export class SearchService {
|
||||
async getExploreData(authUser: AuthUserDto): Promise<SearchExploreItem<AssetResponseDto>[]> {
|
||||
this.assertEnabled();
|
||||
const results = await this.searchRepository.explore(authUser.id);
|
||||
const lookup = await this.getLookupMap(
|
||||
results.reduce(
|
||||
(ids: string[], result: SearchExploreItem<AssetEntity>) => [
|
||||
...ids,
|
||||
...result.items.map((item) => item.data.id),
|
||||
],
|
||||
[],
|
||||
),
|
||||
);
|
||||
|
||||
return results.map(({ fieldName, items }) => ({
|
||||
fieldName,
|
||||
items: items.map(({ value, data }) => ({ value, data: mapAsset(data) })),
|
||||
items: items
|
||||
.map(({ value, data }) => ({ value, data: lookup[data.id] }))
|
||||
.filter(({ data }) => !!data)
|
||||
.map(({ value, data }) => ({ value, data: mapAsset(data) })),
|
||||
}));
|
||||
}
|
||||
|
||||
@ -132,10 +145,17 @@ export class SearchService {
|
||||
}
|
||||
|
||||
const albums = await this.searchRepository.searchAlbums(query, filters);
|
||||
const lookup = await this.getLookupMap(assets.items.map((asset) => asset.id));
|
||||
|
||||
return {
|
||||
albums: { ...albums, items: albums.items.map(mapAlbum) },
|
||||
assets: { ...assets, items: assets.items.map(mapAsset) },
|
||||
assets: {
|
||||
...assets,
|
||||
items: assets.items
|
||||
.map((item) => lookup[item.id])
|
||||
.filter((item) => !!item)
|
||||
.map(mapAsset),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -358,4 +378,13 @@ export class SearchService {
|
||||
const [assetId, personId] = key.split('|');
|
||||
return { assetId, personId };
|
||||
}
|
||||
|
||||
private async getLookupMap(assetIds: string[]) {
|
||||
const assets = await this.assetRepository.getByIds(assetIds);
|
||||
const lookup: Record<string, AssetEntity> = {};
|
||||
for (const asset of assets) {
|
||||
lookup[asset.id] = asset;
|
||||
}
|
||||
return lookup;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import { IAssetRepository } from '../src';
|
||||
|
||||
export const newAssetRepositoryMock = (): jest.Mocked<IAssetRepository> => {
|
||||
return {
|
||||
getByIds: jest.fn(),
|
||||
getByIds: jest.fn().mockResolvedValue([]),
|
||||
getWithout: jest.fn(),
|
||||
getWith: jest.fn(),
|
||||
getFirstAssetForAlbumId: jest.fn(),
|
||||
|
@ -140,8 +140,8 @@
|
||||
"coverageThreshold": {
|
||||
"./libs/domain/": {
|
||||
"branches": 80,
|
||||
"functions": 87,
|
||||
"lines": 93.7,
|
||||
"functions": 85,
|
||||
"lines": 93,
|
||||
"statements": 93
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user