Update sizes with SQL, instead of a full rescan
This commit is contained in:
parent
8bfaa0ad9d
commit
cf90f0a245
|
@ -16,12 +16,15 @@ alter table album
|
||||||
add size integer default 0 not null;
|
add size integer default 0 not null;
|
||||||
create index if not exists album_size
|
create index if not exists album_size
|
||||||
on album(size);
|
on album(size);
|
||||||
`)
|
|
||||||
if err != nil {
|
update album set size = ifnull((
|
||||||
return err
|
select sum(f.size)
|
||||||
}
|
from media_file f
|
||||||
notice(tx, "A full rescan will be performed to calculate album sizes.")
|
where f.album_id = album.id
|
||||||
return forceFullRescan(tx)
|
), 0)
|
||||||
|
where id not null;`)
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Down20201010162350(tx *sql.Tx) error {
|
func Down20201010162350(tx *sql.Tx) error {
|
||||||
|
|
|
@ -17,6 +17,13 @@ alter table artist
|
||||||
create index if not exists artist_size
|
create index if not exists artist_size
|
||||||
on artist(size);
|
on artist(size);
|
||||||
|
|
||||||
|
update artist set size = ifnull((
|
||||||
|
select sum(f.size)
|
||||||
|
from album f
|
||||||
|
where f.album_artist_id = artist.id
|
||||||
|
), 0)
|
||||||
|
where id not null;
|
||||||
|
|
||||||
alter table playlist
|
alter table playlist
|
||||||
add size integer default 0 not null;
|
add size integer default 0 not null;
|
||||||
create index if not exists playlist_size
|
create index if not exists playlist_size
|
||||||
|
@ -29,11 +36,7 @@ update playlist set size = ifnull((
|
||||||
where pt.playlist_id = playlist.id
|
where pt.playlist_id = playlist.id
|
||||||
), 0);`)
|
), 0);`)
|
||||||
|
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
notice(tx, "A full rescan will be performed to calculate artists (discographies) and playlists sizes.")
|
|
||||||
return forceFullRescan(tx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Down20201012210022(tx *sql.Tx) error {
|
func Down20201012210022(tx *sql.Tx) error {
|
||||||
|
|
|
@ -29,9 +29,12 @@ update media_file set updated_at = '0001-01-01';
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var once sync.Once
|
var (
|
||||||
|
once sync.Once
|
||||||
|
initialized bool
|
||||||
|
)
|
||||||
|
|
||||||
func isDBInitialized(tx *sql.Tx) (initialized bool) {
|
func isDBInitialized(tx *sql.Tx) bool {
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
rows, err := tx.Query("select count(*) from property where id=?", consts.InitialSetupFlagKey)
|
rows, err := tx.Query("select count(*) from property where id=?", consts.InitialSetupFlagKey)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
Loading…
Reference in New Issue