Skip to content

Commit

Permalink
feat(db): add a covering index on tracks (album_id, length)
Browse files Browse the repository at this point in the history
Co-authored-by: Artem Tarasov <[email protected]>

closes #508
  • Loading branch information
sentriz committed Jan 15, 2025
1 parent 718686a commit cd82b74
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions db/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func (db *DB) Migrate(ctx MigrationContext) error {
construct(ctx, "202311082304", migrateTemporaryDisplayAlbumArtist),
construct(ctx, "202312110003", migrateAddExtraIndexes),
construct(ctx, "202405301140", migrateAddReplayGainFields),
construct(ctx, "202501152035", migrateTrackAddIndexOnAlbumID),
construct(ctx, "202501152036", migrateAlbumAddIndexOnParentID),
}

return gormigrate.
Expand Down Expand Up @@ -818,3 +820,15 @@ func migrateAddExtraIndexes(tx *gorm.DB, _ MigrationContext) error {
func migrateAddReplayGainFields(tx *gorm.DB, _ MigrationContext) error {
return tx.AutoMigrate(Track{}).Error
}

func migrateTrackAddIndexOnAlbumID(tx *gorm.DB, _ MigrationContext) error {
return tx.Exec(`
CREATE INDEX idx_tracks_album_id ON "tracks" (album_id, length);
`).Error
}

func migrateAlbumAddIndexOnParentID(tx *gorm.DB, _ MigrationContext) error {
return tx.Exec(`
CREATE INDEX idx_albums_parent_id ON "albums" (parent_id);
`).Error
}

0 comments on commit cd82b74

Please sign in to comment.