Add size to album details (#561)

* add size to album details

for #534

* addressing review comments:

* create index album(size)
* remove unneeded Size field from refresh struct
* add whitespace to album details
* add size to album list view

* prettier
This commit is contained in:
Jay R. Wren 2020-10-12 11:10:07 -04:00 committed by GitHub
parent c60e56828b
commit fd6edf967f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 4 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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")

View File

@ -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 }) => {
<Typography component="p">
{record.songCount}{' '}
{translate('resources.song.name', { smart_count: record.songCount })}{' '}
· <DurationField record={record} source={'duration'} />
· <DurationField record={record} source={'duration'} /> ·{' '}
<SizeField record={record} source="size" />
</Typography>
<StarButton record={record} resource={'album'} size={'large'} />
</CardContent>

View File

@ -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) => {
<TextField source="genre" />
<BooleanField source="compilation" />
<DateField source="updatedAt" showTime />
<SizeField source="size" />
</SimpleShowLayout>
</Show>
)