1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

fixing case sensitivity issue with PersonManager

This commit is contained in:
Patrik J. Braun 2020-01-01 20:26:59 +01:00
parent 0e52f149ee
commit 83f3def727
3 changed files with 42 additions and 15 deletions

View File

@ -44,6 +44,15 @@ export class PersonManager implements IPersonManager {
const hasAll = names.reduce((prev, name) => prev && !!this.samplePhotos[name], true);
if (!hasAll) {
const connection = await SQLConnection.getConnection();
const namesObj: any = {};
let queryStr = '';
names.forEach((n, i) => {
if (i > 0) {
queryStr += ', ';
}
queryStr += ':n' + i + ' COLLATE utf8_general_ci';
namesObj['n' + i] = n;
});
const rawAndEntities = await (connection
.getRepository(MediaEntity)
.createQueryBuilder('media') as SelectQueryBuilder<MediaEntity>)
@ -52,19 +61,19 @@ export class PersonManager implements IPersonManager {
.leftJoin('media.directory', 'directory')
.leftJoinAndSelect('media.metadata.faces', 'faces')
.leftJoin('faces.person', 'person')
.groupBy('person.name')
.orWhere(`person.name IN (:...names) COLLATE utf8_general_ci`, {names: names}).getRawAndEntities();
.groupBy('person.name, media.name, media.id, directory.name, faces.id')
.orWhere(`lower(person.name) IN (:...names)`, {names: names.map(n => n.toLowerCase())}).getRawAndEntities();
for (let i = 0; i < rawAndEntities.raw.length; ++i) {
this.samplePhotos[rawAndEntities.raw[i].person_name] =
this.samplePhotos[rawAndEntities.raw[i].person_name.toLowerCase()] =
Utils.clone(rawAndEntities.entities.find(m => m.name === rawAndEntities.raw[i].media_name));
this.samplePhotos[rawAndEntities.raw[i].person_name].metadata.faces = [FaceRegionEntry.fromRawToDTO(rawAndEntities.raw[i])];
this.samplePhotos[rawAndEntities.raw[i].person_name.toLowerCase()].metadata.faces = [FaceRegionEntry.fromRawToDTO(rawAndEntities.raw[i])];
}
}
const photoMap: { [key: string]: PhotoDTO } = {};
names.forEach(n => photoMap[n] = this.samplePhotos[n]);
names.forEach(n => photoMap[n] = this.samplePhotos[n.toLowerCase()]);
return photoMap;
}

View File

@ -128,7 +128,7 @@ export function translationsFactory(locale: string) {
if (locale === 'en') {
return '';
}
return (<any>require(`raw-loader!../translate/messages.${locale}.xlf`)).default;
return (<any>require(`raw-loader!../translate/ts-only-msg.fr.xlf`)).default;
}
@NgModule({

View File

@ -68,27 +68,45 @@ describe('PersonManager', (sqlHelper: SQLTestHelper) => {
});
it('should get sample photos', async () => {
const pm = new PersonManager();
const mapPhoto = (photo: PhotoDTO) => {
const map: { [key: string]: PhotoDTO } = {};
p.metadata.faces.forEach(face => {
photo.metadata.faces.forEach(face => {
map[face.name] = <any>{
id: p.id,
name: p.name,
id: photo.id,
name: photo.name,
directory: {
path: p.directory.path,
name: p.directory.name,
path: photo.directory.path,
name: photo.directory.name,
},
metadata: {
size: p.metadata.size,
faces: [p.metadata.faces.find(f => f.name === face.name)]
size: photo.metadata.size,
faces: [photo.metadata.faces.find(f => f.name === face.name)]
},
readyIcon: false,
readyThumbnails: []
};
});
return map;
};
it('should get sample photos', async () => {
const pm = new PersonManager();
const map = mapPhoto(p);
expect(await pm.getSamplePhotos(p.metadata.faces.map(f => f.name))).to.deep.equal(map);
});
it('should get sample photos case insensitive', async () => {
const pm = new PersonManager();
const map = mapPhoto(p);
for (const k of Object.keys(map)) {
if (k.toLowerCase() !== k) {
map[k.toLowerCase()] = map[k];
delete map[k];
}
}
expect(await pm.getSamplePhotos(p.metadata.faces.map(f => f.name.toLowerCase()))).to.deep.equal(map);
});
});