Skip to content

Commit

Permalink
fix: songs from external collections are treated as internal (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
shayded-exe committed May 13, 2021
2 parents 687aebd + 03ecd72 commit f6e9e03
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/engine/1.6/engine-db-1_6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class EngineDB_1_6 extends EngineDB {
trackId: track.id,
trackIdInOriginDatabase: track.id,
trackNumber: i + 1,
databaseUuid: this.databaseUuid,
databaseUuid: this.uuid,
})),
);
}
Expand All @@ -107,7 +107,11 @@ export class EngineDB_1_6 extends EngineDB {
async getTracks(): Promise<publicSchema.Track[]> {
const tracks = await this.getTracksInternal();

return tracks.map(track => ({ ...track, ...track.meta }));
return tracks.map(track => ({
...track,
...track.meta,
isBeatGridLocked: !!track.isBeatGridLocked,
}));
}

private async getTracksInternal(): Promise<schema.TrackWithMeta[]> {
Expand All @@ -124,7 +128,8 @@ export class EngineDB_1_6 extends EngineDB {
'trackType',
'year',
])
.whereNotNull('path');
.whereNotNull('path')
.andWhere('isExternalTrack', 0);
const textMetas = await this.table('MetaData').select('*');
const textMetaMap = groupBy(textMetas, x => x.id);
const intMetas = await this.table('MetaDataInteger').select('*');
Expand Down
4 changes: 2 additions & 2 deletions src/engine/1.6/schema-1_6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export interface Track {
bitrate: number;
bpmAnalyzed: number;
filename: string;
isBeatGridLocked: boolean;
isExternalTrack: boolean;
isBeatGridLocked: IntBoolean;
isExternalTrack: IntBoolean;
length: number;
path: string;
trackType: TrackType;
Expand Down
5 changes: 3 additions & 2 deletions src/engine/2.0/engine-db-2_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class EngineDB_2_0 extends EngineDB {
? 0
: lastEntityId + 2 + i,
membershipReference: 0,
databaseUuid: this.databaseUuid,
databaseUuid: this.uuid,
})),
);
}
Expand Down Expand Up @@ -150,7 +150,8 @@ export class EngineDB_2_0 extends EngineDB {
'title',
'year',
])
.whereNotNull('path');
.whereNotNull('path')
.andWhere('originDatabaseUuid', this.uuid);
}

async updateTrackPaths(tracks: publicSchema.Track[]) {
Expand Down
10 changes: 6 additions & 4 deletions src/engine/engine-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import { EngineVersion } from './version-detection';
export abstract class EngineDB {
protected readonly knex: Knex;

protected databaseUuid!: string;
protected schemaInfo!: schema.Information;

abstract get version(): EngineVersion;

get uuid(): string {
return this.schemaInfo.uuid;
}

protected constructor(private readonly dbPath: string) {
this.knex = knex({
client: 'sqlite3',
Expand All @@ -22,9 +26,7 @@ export abstract class EngineDB {

protected async init() {
await this.backup();
const { uuid } = await this.getSchemaInfo();

this.databaseUuid = uuid;
this.schemaInfo = await this.getSchemaInfo();
}

async disconnect() {
Expand Down

0 comments on commit f6e9e03

Please sign in to comment.