Skip to content

Commit

Permalink
Remove slow and unncessary resetClones function
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyBoo6 committed Apr 30, 2024
1 parent ad22997 commit 95a8663
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 17 deletions.
7 changes: 3 additions & 4 deletions server/src/cache/clone-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ export function generateImageCloneMap(
): ExecutorPromise<any> {
return execute(
async () => {
// First reset the clone map.
await database.resetClones();

// Now find all phashed
const imagesRaw = await database.subsetFields(
{ type: { equalsAll: ['still'] }, phashed: true, duplicateOf: { exists: false } },
Expand All @@ -55,7 +52,7 @@ export function generateImageCloneMap(
return {
hash: image.hash,
phash: image.phash!,
clones: image.clones,
clones: [],
};
});

Expand Down Expand Up @@ -109,6 +106,8 @@ export function generateImageCloneMap(
if (data.err) {
reject(data.err);
} else if (data.clones) {
// data.clones is always set unless there is an error.
// That means this is a clear operation too.
database
.saveMedia(data.hash, {
clones: data.clones.map((c) => c.hash),
Expand Down
5 changes: 0 additions & 5 deletions server/src/database/mongodb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,6 @@ export class MongoConnector extends Database {
return undefined;
}

public async resetClones(): Promise<void> {
const collection = this.db.collection<BaseMedia>('media');
await collection.updateMany({}, { $unset: { clones: '' } });
}

public async resetAutoTags(): Promise<void> {
const collection = this.db.collection<BaseMedia>('media');
const result = await collection.updateMany({ autoTags: { $exists: true } }, { $unset: { autoTags: '' } });
Expand Down
7 changes: 0 additions & 7 deletions server/src/database/sqlite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,6 @@ export class SqliteConnector extends Database {
return Promise.resolve();
}

public resetClones(): Promise<void> {
this.db.exec(
'UPDATE `media` SET `clones` = NULL WHERE `hash` IN (SELECT `hash` FROM `media` WHERE `clones` IS NOT NULL)',
);
return Promise.resolve();
}

public async resetAutoTags(): Promise<void> {
this.db.exec(
'UPDATE `media` SET `auto_tags` = NULL WHERE `hash` IN (SELECT `hash` FROM `media` WHERE `auto_tags` IS NOT NULL)',
Expand Down
1 change: 0 additions & 1 deletion server/src/types/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export abstract class Database {

// Utility
public abstract close(): Promise<void>;
public abstract resetClones(): Promise<void>;
public abstract resetAutoTags(): Promise<void>;

// Clears data from all tables. Implementation should check TEST_MODE=1 is set.
Expand Down

0 comments on commit 95a8663

Please sign in to comment.