mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
remove transaction and format:fix
This commit is contained in:
parent
c503422309
commit
d7cdde0153
3 changed files with 64 additions and 53 deletions
|
|
@ -163,8 +163,7 @@ export class TagRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteEmptyTags() {
|
async deleteEmptyTags() {
|
||||||
await this.db.transaction().execute(async (tx) => {
|
const result = await this.db
|
||||||
const result = await tx
|
|
||||||
.deleteFrom('tag')
|
.deleteFrom('tag')
|
||||||
.where('id', 'not in', (eb) => eb.selectFrom('tag_asset').select('tagsId'))
|
.where('id', 'not in', (eb) => eb.selectFrom('tag_asset').select('tagsId'))
|
||||||
.where('id', 'not in', (eb) =>
|
.where('id', 'not in', (eb) =>
|
||||||
|
|
@ -185,6 +184,5 @@ export class TagRepository {
|
||||||
if (deletedRows > 0) {
|
if (deletedRows > 0) {
|
||||||
this.logger.log(`Deleted ${deletedRows} empty tags`);
|
this.logger.log(`Deleted ${deletedRows} empty tags`);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ import { StorageRepository } from 'src/repositories/storage.repository';
|
||||||
import { SyncCheckpointRepository } from 'src/repositories/sync-checkpoint.repository';
|
import { SyncCheckpointRepository } from 'src/repositories/sync-checkpoint.repository';
|
||||||
import { SyncRepository } from 'src/repositories/sync.repository';
|
import { SyncRepository } from 'src/repositories/sync.repository';
|
||||||
import { SystemMetadataRepository } from 'src/repositories/system-metadata.repository';
|
import { SystemMetadataRepository } from 'src/repositories/system-metadata.repository';
|
||||||
import { TelemetryRepository } from 'src/repositories/telemetry.repository';
|
|
||||||
import { TagRepository } from 'src/repositories/tag.repository';
|
import { TagRepository } from 'src/repositories/tag.repository';
|
||||||
|
import { TelemetryRepository } from 'src/repositories/telemetry.repository';
|
||||||
import { UserRepository } from 'src/repositories/user.repository';
|
import { UserRepository } from 'src/repositories/user.repository';
|
||||||
import { VersionHistoryRepository } from 'src/repositories/version-history.repository';
|
import { VersionHistoryRepository } from 'src/repositories/version-history.repository';
|
||||||
import { DB } from 'src/schema';
|
import { DB } from 'src/schema';
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import { Kysely } from "kysely";
|
import { Kysely } from 'kysely';
|
||||||
import { JobStatus } from "src/enum";
|
import { JobStatus } from 'src/enum';
|
||||||
import { AccessRepository } from "src/repositories/access.repository";
|
import { AccessRepository } from 'src/repositories/access.repository';
|
||||||
import { LoggingRepository } from "src/repositories/logging.repository";
|
import { LoggingRepository } from 'src/repositories/logging.repository';
|
||||||
import { TagRepository } from "src/repositories/tag.repository";
|
import { TagRepository } from 'src/repositories/tag.repository';
|
||||||
import { DB } from "src/schema";
|
import { DB } from 'src/schema';
|
||||||
import { TagService } from "src/services/tag.service";
|
import { TagService } from 'src/services/tag.service';
|
||||||
import { newMediumService } from "test/medium.factory";
|
import { newMediumService } from 'test/medium.factory';
|
||||||
import { getKyselyDB } from "test/utils";
|
import { getKyselyDB } from 'test/utils';
|
||||||
|
|
||||||
let defaultDatabase: Kysely<DB>;
|
let defaultDatabase: Kysely<DB>;
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ describe(TagService.name, () => {
|
||||||
await expect(tagRepo.getByValue(user.id, 'tag-1')).resolves.toEqual(expect.objectContaining({ id: tag.id }));
|
await expect(tagRepo.getByValue(user.id, 'tag-1')).resolves.toEqual(expect.objectContaining({ id: tag.id }));
|
||||||
await expect(sut.handleTagCleanup()).resolves.toBe(JobStatus.Success);
|
await expect(sut.handleTagCleanup()).resolves.toBe(JobStatus.Success);
|
||||||
await expect(tagRepo.getByValue(user.id, 'tag-1')).resolves.toEqual(expect.objectContaining({ id: tag.id }));
|
await expect(tagRepo.getByValue(user.id, 'tag-1')).resolves.toEqual(expect.objectContaining({ id: tag.id }));
|
||||||
})
|
});
|
||||||
|
|
||||||
it('hierarchical tag exists, and the parent is connected to an asset, and the child is deleted', async () => {
|
it('hierarchical tag exists, and the parent is connected to an asset, and the child is deleted', async () => {
|
||||||
const { sut, ctx } = setup();
|
const { sut, ctx } = setup();
|
||||||
|
|
@ -59,12 +59,18 @@ describe(TagService.name, () => {
|
||||||
|
|
||||||
await ctx.newTagAsset({ tagIds: [parentTag.id], assetIds: [asset.id] });
|
await ctx.newTagAsset({ tagIds: [parentTag.id], assetIds: [asset.id] });
|
||||||
|
|
||||||
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(expect.objectContaining({ id: parentTag.id }));
|
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(
|
||||||
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toEqual(expect.objectContaining({ id: childrenTag.id }));
|
expect.objectContaining({ id: parentTag.id }),
|
||||||
|
);
|
||||||
|
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toEqual(
|
||||||
|
expect.objectContaining({ id: childrenTag.id }),
|
||||||
|
);
|
||||||
await expect(sut.handleTagCleanup()).resolves.toBe(JobStatus.Success);
|
await expect(sut.handleTagCleanup()).resolves.toBe(JobStatus.Success);
|
||||||
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(expect.objectContaining({ id: parentTag.id }));
|
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(
|
||||||
|
expect.objectContaining({ id: parentTag.id }),
|
||||||
|
);
|
||||||
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toBeUndefined();
|
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toBeUndefined();
|
||||||
})
|
});
|
||||||
|
|
||||||
it('hierarchical tag exists, and only the child is connected to an asset, and nothing is deleted', async () => {
|
it('hierarchical tag exists, and only the child is connected to an asset, and nothing is deleted', async () => {
|
||||||
const { sut, ctx } = setup();
|
const { sut, ctx } = setup();
|
||||||
|
|
@ -76,12 +82,19 @@ describe(TagService.name, () => {
|
||||||
|
|
||||||
await ctx.newTagAsset({ tagIds: [childrenTag.id], assetIds: [asset.id] });
|
await ctx.newTagAsset({ tagIds: [childrenTag.id], assetIds: [asset.id] });
|
||||||
|
|
||||||
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(expect.objectContaining({ id: parentTag.id }));
|
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(
|
||||||
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toEqual(expect.objectContaining({ id: childrenTag.id }));
|
expect.objectContaining({ id: parentTag.id }),
|
||||||
|
);
|
||||||
|
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toEqual(
|
||||||
|
expect.objectContaining({ id: childrenTag.id }),
|
||||||
|
);
|
||||||
await expect(sut.handleTagCleanup()).resolves.toBe(JobStatus.Success);
|
await expect(sut.handleTagCleanup()).resolves.toBe(JobStatus.Success);
|
||||||
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(expect.objectContaining({ id: parentTag.id }));
|
await expect(tagRepo.getByValue(user.id, 'parent')).resolves.toEqual(
|
||||||
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toEqual(expect.objectContaining({ id: childrenTag.id }));
|
expect.objectContaining({ id: parentTag.id }),
|
||||||
})
|
);
|
||||||
|
await expect(tagRepo.getByValue(user.id, 'child')).resolves.toEqual(
|
||||||
})
|
expect.objectContaining({ id: childrenTag.id }),
|
||||||
})
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue