add indexes
This commit is contained in:
@@ -208,6 +208,7 @@ func createDatabase() {
|
|||||||
|
|
||||||
func cleanDatabase() {
|
func cleanDatabase() {
|
||||||
// delete tracks not on filesystem
|
// delete tracks not on filesystem
|
||||||
|
o := time.Now()
|
||||||
var tracks []*db.Track
|
var tracks []*db.Track
|
||||||
tx.Select("id, path").Find(&tracks)
|
tx.Select("id, path").Find(&tracks)
|
||||||
for _, track := range tracks {
|
for _, track := range tracks {
|
||||||
@@ -218,6 +219,8 @@ func cleanDatabase() {
|
|||||||
tx.Delete(&track)
|
tx.Delete(&track)
|
||||||
log.Println("removed", track.Path)
|
log.Println("removed", track.Path)
|
||||||
}
|
}
|
||||||
|
fmt.Println("ONE", time.Since(o))
|
||||||
|
o = time.Now()
|
||||||
// delete albums without tracks
|
// delete albums without tracks
|
||||||
tx.Exec(`
|
tx.Exec(`
|
||||||
DELETE FROM albums
|
DELETE FROM albums
|
||||||
@@ -225,6 +228,8 @@ func cleanDatabase() {
|
|||||||
FROM tracks
|
FROM tracks
|
||||||
WHERE album_id = albums.id) = 0;
|
WHERE album_id = albums.id) = 0;
|
||||||
`)
|
`)
|
||||||
|
fmt.Println("TWO", time.Since(o))
|
||||||
|
o = time.Now()
|
||||||
// delete artists without tracks
|
// delete artists without tracks
|
||||||
tx.Exec(`
|
tx.Exec(`
|
||||||
DELETE FROM album_artists
|
DELETE FROM album_artists
|
||||||
@@ -232,6 +237,7 @@ func cleanDatabase() {
|
|||||||
FROM albums
|
FROM albums
|
||||||
WHERE album_artist_id = album_artists.id) = 0;
|
WHERE album_artist_id = album_artists.id) = 0;
|
||||||
`)
|
`)
|
||||||
|
fmt.Println("THREE", time.Since(o))
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ type Album struct {
|
|||||||
IDBase
|
IDBase
|
||||||
CrudBase
|
CrudBase
|
||||||
AlbumArtist AlbumArtist
|
AlbumArtist AlbumArtist
|
||||||
AlbumArtistID int
|
AlbumArtistID int `gorm:"index"`
|
||||||
Title string `gorm:"not null;index"`
|
Title string `gorm:"not null;index"`
|
||||||
Tracks []Track
|
Tracks []Track
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ type Track struct {
|
|||||||
IDBase
|
IDBase
|
||||||
CrudBase
|
CrudBase
|
||||||
Album Album
|
Album Album
|
||||||
AlbumID int
|
AlbumID int `gorm:"index"`
|
||||||
AlbumArtist AlbumArtist
|
AlbumArtist AlbumArtist
|
||||||
AlbumArtistID int
|
AlbumArtistID int
|
||||||
Artist string
|
Artist string
|
||||||
|
|||||||
Reference in New Issue
Block a user