fix(server): "all" button for facial recognition deleting faces instead of unassigning them (#13042)

* unassign faces instead of deleting them

* formatting
This commit is contained in:
Mert
2024-09-30 00:29:14 -04:00
committed by GitHub
parent 9b309e84c9
commit 2f13db51df
5 changed files with 39 additions and 29 deletions

View File

@@ -660,7 +660,7 @@ describe(PersonService.name, () => {
expect(systemMock.set).not.toHaveBeenCalled();
});
it('should delete existing people and faces if forced', async () => {
it('should delete existing people if forced', async () => {
jobMock.getJobCounts.mockResolvedValue({ active: 1, waiting: 0, paused: 0, completed: 0, failed: 0, delayed: 0 });
personMock.getAll.mockResolvedValue({
items: [faceStub.face1.person, personStub.randomPerson],
@@ -675,7 +675,8 @@ describe(PersonService.name, () => {
await sut.handleQueueRecognizeFaces({ force: true });
expect(personMock.deleteAllFaces).toHaveBeenCalledWith({ sourceType: SourceType.MACHINE_LEARNING });
expect(personMock.deleteFaces).not.toHaveBeenCalled();
expect(personMock.unassignFaces).toHaveBeenCalledWith({ sourceType: SourceType.MACHINE_LEARNING });
expect(jobMock.queueAll).toHaveBeenCalledWith([
{
name: JobName.FACIAL_RECOGNITION,

View File

@@ -276,16 +276,6 @@ export class PersonService {
this.logger.debug(`Deleted ${people.length} people`);
}
private async deleteAllPeople() {
const personPagination = usePagination(JOBS_ASSET_PAGINATION_SIZE, (pagination) =>
this.repository.getAll({ ...pagination, skip: 0 }),
);
for await (const people of personPagination) {
await this.delete(people); // deletes thumbnails too
}
}
async handlePersonCleanup(): Promise<JobStatus> {
const people = await this.repository.getAllWithoutFaces();
await this.delete(people);
@@ -299,7 +289,7 @@ export class PersonService {
}
if (force) {
await this.repository.deleteAllFaces({ sourceType: SourceType.MACHINE_LEARNING });
await this.repository.deleteFaces({ sourceType: SourceType.MACHINE_LEARNING });
await this.handlePersonCleanup();
}
@@ -407,7 +397,7 @@ export class PersonService {
const { waiting } = await this.jobRepository.getJobCounts(QueueName.FACIAL_RECOGNITION);
if (force) {
await this.repository.deleteAllFaces({ sourceType: SourceType.MACHINE_LEARNING });
await this.repository.unassignFaces({ sourceType: SourceType.MACHINE_LEARNING });
await this.handlePersonCleanup();
} else if (waiting) {
this.logger.debug(