mirror of
https://github.com/immich-app/immich.git
synced 2026-01-21 19:27:23 -05:00
The searchAssetBuilder was incorrectly adding withFacesAndPeople select when personIds was provided. This caused a SQL error because the subquery referenced asset.id which wasn't selected in statistics queries (only count(*) was selected). The fix removes personIds from the condition that triggers adding faces data to the select. The hasPeople filter (for personIds) is still applied correctly for filtering. Fixes #25003 Signed-off-by: majiayu000 <1835304752@qq.com>
92 lines
3.0 KiB
TypeScript
92 lines
3.0 KiB
TypeScript
import { Kysely } from 'kysely';
|
|
import { AccessRepository } from 'src/repositories/access.repository';
|
|
import { AssetRepository } from 'src/repositories/asset.repository';
|
|
import { DatabaseRepository } from 'src/repositories/database.repository';
|
|
import { LoggingRepository } from 'src/repositories/logging.repository';
|
|
import { PartnerRepository } from 'src/repositories/partner.repository';
|
|
import { PersonRepository } from 'src/repositories/person.repository';
|
|
import { SearchRepository } from 'src/repositories/search.repository';
|
|
import { DB } from 'src/schema';
|
|
import { SearchService } from 'src/services/search.service';
|
|
import { newMediumService } from 'test/medium.factory';
|
|
import { factory } from 'test/small.factory';
|
|
import { getKyselyDB } from 'test/utils';
|
|
|
|
let defaultDatabase: Kysely<DB>;
|
|
|
|
const setup = (db?: Kysely<DB>) => {
|
|
return newMediumService(SearchService, {
|
|
database: db || defaultDatabase,
|
|
real: [
|
|
AccessRepository,
|
|
AssetRepository,
|
|
DatabaseRepository,
|
|
SearchRepository,
|
|
PartnerRepository,
|
|
PersonRepository,
|
|
],
|
|
mock: [LoggingRepository],
|
|
});
|
|
};
|
|
|
|
beforeAll(async () => {
|
|
defaultDatabase = await getKyselyDB();
|
|
});
|
|
|
|
describe(SearchService.name, () => {
|
|
it('should work', () => {
|
|
const { sut } = setup();
|
|
expect(sut).toBeDefined();
|
|
});
|
|
|
|
it('should return assets', async () => {
|
|
const { sut, ctx } = setup();
|
|
const { user } = await ctx.newUser();
|
|
|
|
const assets = [];
|
|
const sizes = [12_334, 599, 123_456];
|
|
|
|
for (let i = 0; i < sizes.length; i++) {
|
|
const { asset } = await ctx.newAsset({ ownerId: user.id });
|
|
await ctx.newExif({ assetId: asset.id, fileSizeInByte: sizes[i] });
|
|
assets.push(asset);
|
|
}
|
|
|
|
const auth = factory.auth({ user: { id: user.id } });
|
|
|
|
await expect(sut.searchLargeAssets(auth, {})).resolves.toEqual([
|
|
expect.objectContaining({ id: assets[2].id }),
|
|
expect.objectContaining({ id: assets[0].id }),
|
|
expect.objectContaining({ id: assets[1].id }),
|
|
]);
|
|
});
|
|
|
|
describe('searchStatistics', () => {
|
|
it('should return statistics when filtering by personIds', async () => {
|
|
const { sut, ctx } = setup();
|
|
const { user } = await ctx.newUser();
|
|
const { asset } = await ctx.newAsset({ ownerId: user.id });
|
|
const { person } = await ctx.newPerson({ ownerId: user.id });
|
|
await ctx.newAssetFace({ assetId: asset.id, personId: person.id });
|
|
|
|
const auth = factory.auth({ user: { id: user.id } });
|
|
|
|
const result = await sut.searchStatistics(auth, { personIds: [person.id] });
|
|
|
|
expect(result).toEqual({ total: 1 });
|
|
});
|
|
|
|
it('should return zero when no assets match the personIds filter', async () => {
|
|
const { sut, ctx } = setup();
|
|
const { user } = await ctx.newUser();
|
|
const { person } = await ctx.newPerson({ ownerId: user.id });
|
|
|
|
const auth = factory.auth({ user: { id: user.id } });
|
|
|
|
const result = await sut.searchStatistics(auth, { personIds: [person.id] });
|
|
|
|
expect(result).toEqual({ total: 0 });
|
|
});
|
|
});
|
|
});
|