Skip to content

Commit

Permalink
Update deleted media path when deleted hash found
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyBoo6 committed Feb 4, 2024
1 parent 9c1aa9c commit 4f7a365
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions client/src/app/services/ui.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ export class UiService {
offset > 0
? {
dir: { after: dir },
sortBy: 'path',
sortBy: 'dir',
sortDirection: 'ASC',
limit: 1,
}
: {
dir: { before: dir },
sortBy: 'path',
sortBy: 'dir',
sortDirection: 'DESC',
limit: 1,
};
Expand Down
2 changes: 1 addition & 1 deletion common/src/search.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface SubsetConstraints {
keywordSearch?: string;
// Object ID, if set can sort by order.
playlist?: string;
sortBy?: 'hashDate' | 'recommended' | 'rating' | 'length' | 'createdAt' | 'path' | 'order';
sortBy?: 'hashDate' | 'recommended' | 'rating' | 'length' | 'createdAt' | 'path' | 'order' | 'dir';
// If not set defaults to whatever is sensible for the sortBy field.
sortDirection?: 'ASC' | 'DESC';
// Checks that metadata exists
Expand Down
3 changes: 2 additions & 1 deletion server/src/database/mongodb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,8 @@ export class MongoConnector extends Database {
Object.assign(sort, { [constraints.sortBy]: sortDirection || -1 });
break;
case 'order': // Fallthrough
case 'path':
case 'path': // Fallthrough
case 'dir':
Object.assign(sort, { [constraints.sortBy]: sortDirection || 1 });
break;
case 'length': // Fallthrough
Expand Down
2 changes: 0 additions & 2 deletions server/src/database/sqlite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export class SqliteConnector extends Database {
constraintsQuery.query +
') AS `joined_media` WHERE `joined_media`.`hash` = `media`.`hash`';
const values = [...updateQuery.values, ...constraintsQuery.values];
console.log(query, values);
const res = this.db.prepare(query).run(...values) as { changes: number };
return Promise.resolve(res.changes);
}
Expand Down Expand Up @@ -287,7 +286,6 @@ export class SqliteConnector extends Database {
// Searching
public subset(constraints: SubsetConstraints): Promise<string[]> {
const { query, values } = buildMediaQuery(constraints);
console.log(query, values);
const raw = this.db.prepare(query).all(...values) as Array<{ hash: string }>;
return Promise.resolve(raw.map((el) => el.hash));
}
Expand Down
3 changes: 2 additions & 1 deletion server/src/database/sqlite/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,8 @@ export function buildMediaQuery(
constraints.sortDirection = 'DESC';
break;
case 'order': // fallthrough
case 'path':
case 'path': // fallthrough
case 'dir':
constraints.sortDirection = 'ASC';
break;
}
Expand Down
5 changes: 4 additions & 1 deletion server/src/tasks/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export class Indexer {
path: media.path,
});
} else {
if (!(await this.database.isDeletedHash(media.hash))) {
if (await this.database.isDeletedHash(media.hash)) {
// If the hash has been deleted that means this path is new for this hash.
await this.database.addDeleted(media);
} else {
await this.database.saveMedia(media.hash, media);
}
}
Expand Down

0 comments on commit 4f7a365

Please sign in to comment.