diff --git a/Makefile b/Makefile index e120bb315..c4264d120 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ update-snapshots: check_go_env migration: @if [ -z "${name}" ]; then echo "Usage: make migration name=name_of_migration_file"; exit 1; fi - goose -dir db/migrations create ${name} + goose -dir db/migration create ${name} .PHONY: migration setup: download-deps diff --git a/db/migration/20201010162350_add_album_size.go b/db/migration/20201010162350_add_album_size.go new file mode 100644 index 000000000..3963796fb --- /dev/null +++ b/db/migration/20201010162350_add_album_size.go @@ -0,0 +1,30 @@ +package migration + +import ( + "database/sql" + + "github.com/pressly/goose" +) + +func init() { + goose.AddMigration(Up20201010162350, Down20201010162350) +} + +func Up20201010162350(tx *sql.Tx) error { + _, err := tx.Exec(` +alter table album + add size integer default 0 not null; +create index if not exists album_size + on album(size); + `) + if err != nil { + return err + } + notice(tx, "A full rescan will be performed to calculate album sizes.") + return forceFullRescan(tx) +} + +func Down20201010162350(tx *sql.Tx) error { + // This code is executed when the migration is rolled back. + return nil +} diff --git a/model/album.go b/model/album.go index 6d0b74288..9ab192e68 100644 --- a/model/album.go +++ b/model/album.go @@ -27,6 +27,7 @@ type Album struct { OrderAlbumArtistName string `json:"orderAlbumArtistName"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` + Size int `json:"size"` } type Albums []Album diff --git a/persistence/album_repository.go b/persistence/album_repository.go index a7262ecc8..3a59b1286 100644 --- a/persistence/album_repository.go +++ b/persistence/album_repository.go @@ -164,7 +164,8 @@ func (r *albumRepository) refresh(ids ...string) error { f.compilation, f.genre, max(f.year) as max_year, sum(f.duration) as duration, count(f.id) as song_count, a.id as current_id, group_concat(f.disc_subtitle, ' ') as disc_subtitles, - group_concat(f.artist, ' ') as song_artists, group_concat(f.year, ' ') as years`). + group_concat(f.artist, ' ') as song_artists, group_concat(f.year, ' ') as years, + sum(f.size) as size`). From("media_file f"). LeftJoin("album a on f.album_id = a.id"). Where(Eq{"f.album_id": ids}).GroupBy("f.album_id") diff --git a/ui/src/album/AlbumDetails.js b/ui/src/album/AlbumDetails.js index ac01b62e2..b4b3f4ae5 100644 --- a/ui/src/album/AlbumDetails.js +++ b/ui/src/album/AlbumDetails.js @@ -4,7 +4,7 @@ import { useTranslate } from 'react-admin' import Lightbox from 'react-image-lightbox' import 'react-image-lightbox/style.css' import subsonic from '../subsonic' -import { DurationField, formatRange, StarButton } from '../common' +import { DurationField, formatRange, StarButton, SizeField } from '../common' import { ArtistLinkField } from '../common' const AlbumDetails = ({ classes, record }) => { @@ -48,7 +48,8 @@ const AlbumDetails = ({ classes, record }) => { {record.songCount}{' '} {translate('resources.song.name', { smart_count: record.songCount })}{' '} - · + · ·{' '} + diff --git a/ui/src/album/AlbumListView.js b/ui/src/album/AlbumListView.js index a92258b4b..ca0621542 100644 --- a/ui/src/album/AlbumListView.js +++ b/ui/src/album/AlbumListView.js @@ -17,6 +17,7 @@ import { DurationField, RangeField, SimpleList, + SizeField, } from '../common' import { AlbumContextMenu } from '../common' import { makeStyles } from '@material-ui/core/styles' @@ -37,6 +38,7 @@ const AlbumDetails = (props) => { + )