left join when counting parent's children
This commit is contained in:
@@ -9,7 +9,7 @@ type EmbeddedAsset struct {
|
||||
}
|
||||
var Bytes = map[string]*EmbeddedAsset{
|
||||
"pages/change_password.tmpl": &EmbeddedAsset{
|
||||
ModTime: time.Unix(1584664127, 0),
|
||||
ModTime: time.Unix(1584672536, 0),
|
||||
Bytes: []byte{
|
||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||
@@ -37,7 +37,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
||||
0x3e,0x0a,0x3c,0x2f,0x64,0x69,0x76,0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||
}},
|
||||
"pages/login.tmpl": &EmbeddedAsset{
|
||||
ModTime: time.Unix(1584664416, 0),
|
||||
ModTime: time.Unix(1584672536, 0),
|
||||
Bytes: []byte{
|
||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x63,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x22,0x20,0x7d,0x7d,0x0a,0x3c,
|
||||
0x64,0x69,0x76,0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,
|
||||
@@ -60,7 +60,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
||||
0x66,0x6f,0x72,0x6d,0x3e,0x0a,0x3c,0x2f,0x64,0x69,0x76,0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||
}},
|
||||
"pages/home.tmpl": &EmbeddedAsset{
|
||||
ModTime: time.Unix(1584668133, 0),
|
||||
ModTime: time.Unix(1584672536, 0),
|
||||
Bytes: []byte{
|
||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||
@@ -364,7 +364,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
||||
0x3c,0x2f,0x64,0x69,0x76,0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||
}},
|
||||
"pages/delete_user.tmpl": &EmbeddedAsset{
|
||||
ModTime: time.Unix(1584664195, 0),
|
||||
ModTime: time.Unix(1584672536, 0),
|
||||
Bytes: []byte{
|
||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||
@@ -390,7 +390,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
||||
0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||
}},
|
||||
"pages/update_lastfm_api_key.tmpl": &EmbeddedAsset{
|
||||
ModTime: time.Unix(1584664096, 0),
|
||||
ModTime: time.Unix(1584672536, 0),
|
||||
Bytes: []byte{
|
||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||
@@ -431,7 +431,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
||||
0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||
}},
|
||||
"pages/change_own_password.tmpl": &EmbeddedAsset{
|
||||
ModTime: time.Unix(1584664461, 0),
|
||||
ModTime: time.Unix(1584672536, 0),
|
||||
Bytes: []byte{
|
||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||
@@ -457,7 +457,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
||||
0x2f,0x64,0x69,0x76,0x3e,0x0a,0x7b,0x7b,0x20,0x65,0x6e,0x64,0x20,0x7d,0x7d,0x0a,
|
||||
}},
|
||||
"pages/create_user.tmpl": &EmbeddedAsset{
|
||||
ModTime: time.Unix(1584664156, 0),
|
||||
ModTime: time.Unix(1584672536, 0),
|
||||
Bytes: []byte{
|
||||
0x7b,0x7b,0x20,0x64,0x65,0x66,0x69,0x6e,0x65,0x20,0x22,0x75,0x73,0x65,0x72,0x22,0x20,0x7d,0x7d,0x0a,0x3c,0x64,0x69,0x76,
|
||||
0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x70,0x61,0x64,0x64,0x65,0x64,0x20,0x62,0x6f,0x78,0x22,0x3e,0x0a,0x20,0x20,0x20,
|
||||
@@ -10805,7 +10805,7 @@ var Bytes = map[string]*EmbeddedAsset{
|
||||
0x55,0x23,0xfe,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82,
|
||||
}},
|
||||
"static/main.css": &EmbeddedAsset{
|
||||
ModTime: time.Unix(1584667914, 0),
|
||||
ModTime: time.Unix(1584672536, 0),
|
||||
Bytes: []byte{
|
||||
0x3a,0x72,0x6f,0x6f,0x74,0x20,0x7b,0x0a,0x20,0x20,0x2d,0x2d,0x73,0x69,0x7a,0x65,0x3a,0x20,0x31,0x33,0x70,0x78,0x3b,0x0a,
|
||||
0x7d,0x0a,0x0a,0x40,0x6d,0x65,0x64,0x69,0x61,0x20,0x6f,0x6e,0x6c,0x79,0x20,0x73,0x63,0x72,0x65,0x65,0x6e,0x20,0x61,0x6e,
|
||||
|
||||
@@ -23,7 +23,7 @@ func (c *Controller) ServeGetIndexes(r *http.Request) *spec.Response {
|
||||
var folders []*db.Album
|
||||
c.DB.
|
||||
Select("*, count(sub.id) child_count").
|
||||
Joins("JOIN albums sub ON albums.id=sub.parent_id").
|
||||
Joins("LEFT JOIN albums sub ON albums.id=sub.parent_id").
|
||||
Where("albums.parent_id=1").
|
||||
Group("albums.id").
|
||||
Find(&folders)
|
||||
@@ -137,7 +137,7 @@ func (c *Controller) ServeGetAlbumList(r *http.Request) *spec.Response {
|
||||
// of children. it might make sense to store that in the db
|
||||
q.
|
||||
Select("albums.*, count(tracks.id) child_count").
|
||||
Joins("JOIN tracks ON tracks.album_id=albums.id").
|
||||
Joins("LEFT JOIN tracks ON tracks.album_id=albums.id").
|
||||
Group("albums.id").
|
||||
Where("albums.tag_artist_id IS NOT NULL").
|
||||
Offset(params.GetIntOr("offset", 0)).
|
||||
|
||||
@@ -18,7 +18,7 @@ func (c *Controller) ServeGetArtists(r *http.Request) *spec.Response {
|
||||
var artists []*db.Artist
|
||||
c.DB.
|
||||
Select("*, count(sub.id) album_count").
|
||||
Joins("JOIN albums sub ON artists.id=sub.tag_artist_id").
|
||||
Joins("LEFT JOIN albums sub ON artists.id=sub.tag_artist_id").
|
||||
Group("artists.id").
|
||||
Find(&artists)
|
||||
// [a-z#] -> 27
|
||||
@@ -140,7 +140,7 @@ func (c *Controller) ServeGetAlbumListTwo(r *http.Request) *spec.Response {
|
||||
// of children. it might make sense to store that in the db
|
||||
q.
|
||||
Select("albums.*, count(tracks.id) child_count").
|
||||
Joins("JOIN tracks ON tracks.album_id=albums.id").
|
||||
Joins("LEFT JOIN tracks ON tracks.album_id=albums.id").
|
||||
Group("albums.id").
|
||||
Where("albums.tag_artist_id IS NOT NULL").
|
||||
Offset(params.GetIntOr("offset", 0)).
|
||||
@@ -257,7 +257,7 @@ func (c *Controller) ServeGetArtistInfoTwo(r *http.Request) *spec.Response {
|
||||
err = c.DB.
|
||||
Select("artists.*, count(albums.id) album_count").
|
||||
Where("name=?", similarInfo.Name).
|
||||
Joins("JOIN albums ON artists.id=albums.tag_artist_id").
|
||||
Joins("LEFT JOIN albums ON artists.id=albums.tag_artist_id").
|
||||
Group("artists.id").
|
||||
Find(artist).
|
||||
Error
|
||||
|
||||
BIN
server/ctrlsubsonic/testdata/db
vendored
BIN
server/ctrlsubsonic/testdata/db
vendored
Binary file not shown.
@@ -17,6 +17,17 @@
|
||||
"duration": 0,
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "19",
|
||||
"coverArt": "19",
|
||||
"artist": "Ten Years After",
|
||||
"title": "(1967) Ten Years After",
|
||||
"parent": "18",
|
||||
"isDir": true,
|
||||
"songCount": 15,
|
||||
"duration": 0,
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "8",
|
||||
"coverArt": "8",
|
||||
@@ -28,6 +39,17 @@
|
||||
"duration": 0,
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "5",
|
||||
"coverArt": "5",
|
||||
"artist": "A Certain Ratio",
|
||||
"title": "(1994) The Graveyard and the Ballroom",
|
||||
"parent": "4",
|
||||
"isDir": true,
|
||||
"songCount": 14,
|
||||
"duration": 0,
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "16",
|
||||
"coverArt": "16",
|
||||
@@ -51,13 +73,13 @@
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "9",
|
||||
"coverArt": "9",
|
||||
"artist": "13th Floor Lowervators",
|
||||
"title": "(1966) The Psychedelic Sounds of the 13th Floor Elevators",
|
||||
"parent": "7",
|
||||
"id": "21",
|
||||
"coverArt": "21",
|
||||
"artist": "Captain Beefheart",
|
||||
"title": "(1970) Lick My Decals Off, Bitch",
|
||||
"parent": "20",
|
||||
"isDir": true,
|
||||
"songCount": 21,
|
||||
"songCount": 15,
|
||||
"duration": 0,
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
@@ -72,39 +94,6 @@
|
||||
"duration": 0,
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "5",
|
||||
"coverArt": "5",
|
||||
"artist": "A Certain Ratio",
|
||||
"title": "(1994) The Graveyard and the Ballroom",
|
||||
"parent": "4",
|
||||
"isDir": true,
|
||||
"songCount": 14,
|
||||
"duration": 0,
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "19",
|
||||
"coverArt": "19",
|
||||
"artist": "Ten Years After",
|
||||
"title": "(1967) Ten Years After",
|
||||
"parent": "18",
|
||||
"isDir": true,
|
||||
"songCount": 15,
|
||||
"duration": 0,
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "21",
|
||||
"coverArt": "21",
|
||||
"artist": "Captain Beefheart",
|
||||
"title": "(1970) Lick My Decals Off, Bitch",
|
||||
"parent": "20",
|
||||
"isDir": true,
|
||||
"songCount": 15,
|
||||
"duration": 0,
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "6",
|
||||
"artist": "A Certain Ratio",
|
||||
@@ -114,6 +103,17 @@
|
||||
"songCount": 9,
|
||||
"duration": 0,
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "9",
|
||||
"coverArt": "9",
|
||||
"artist": "13th Floor Lowervators",
|
||||
"title": "(1966) The Psychedelic Sounds of the 13th Floor Elevators",
|
||||
"parent": "7",
|
||||
"isDir": true,
|
||||
"songCount": 21,
|
||||
"duration": 0,
|
||||
"created": "0001-01-01T00:00:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -7,20 +7,11 @@
|
||||
"albumList2": {
|
||||
"album": [
|
||||
{
|
||||
"id": "21",
|
||||
"coverArt": "21",
|
||||
"artistId": "7",
|
||||
"artist": "Captain Beefheart & His Magic Band",
|
||||
"name": "Lick My Decals Off, Baby",
|
||||
"songCount": 15,
|
||||
"duration": 0,
|
||||
"created": "2019-06-10T19:26:30.944742894+01:00"
|
||||
},
|
||||
{
|
||||
"id": "6",
|
||||
"artistId": "2",
|
||||
"artist": "A Certain Ratio",
|
||||
"name": "To Each...",
|
||||
"id": "13",
|
||||
"coverArt": "13",
|
||||
"artistId": "4",
|
||||
"artist": "Anikas",
|
||||
"name": "Anika",
|
||||
"songCount": 9,
|
||||
"duration": 0,
|
||||
"created": "2019-05-23T15:12:02.921473302+01:00"
|
||||
@@ -35,26 +26,6 @@
|
||||
"duration": 0,
|
||||
"created": "2019-04-30T16:48:48+01:00"
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"coverArt": "3",
|
||||
"artistId": "1",
|
||||
"artist": "Jah Wobble, The Edge & Holger Czukay",
|
||||
"name": "Snake Charmer",
|
||||
"songCount": 5,
|
||||
"duration": 0,
|
||||
"created": "2019-05-16T22:10:52+01:00"
|
||||
},
|
||||
{
|
||||
"id": "13",
|
||||
"coverArt": "13",
|
||||
"artistId": "4",
|
||||
"artist": "Anikas",
|
||||
"name": "Anika",
|
||||
"songCount": 9,
|
||||
"duration": 0,
|
||||
"created": "2019-05-23T15:12:02.921473302+01:00"
|
||||
},
|
||||
{
|
||||
"id": "8",
|
||||
"coverArt": "8",
|
||||
@@ -75,6 +46,25 @@
|
||||
"duration": 0,
|
||||
"created": "2019-06-13T12:57:24.306717554+01:00"
|
||||
},
|
||||
{
|
||||
"id": "6",
|
||||
"artistId": "2",
|
||||
"artist": "A Certain Ratio",
|
||||
"name": "To Each...",
|
||||
"songCount": 9,
|
||||
"duration": 0,
|
||||
"created": "2019-05-23T15:12:02.921473302+01:00"
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"coverArt": "3",
|
||||
"artistId": "1",
|
||||
"artist": "Jah Wobble, The Edge & Holger Czukay",
|
||||
"name": "Snake Charmer",
|
||||
"songCount": 5,
|
||||
"duration": 0,
|
||||
"created": "2019-05-16T22:10:52+01:00"
|
||||
},
|
||||
{
|
||||
"id": "5",
|
||||
"coverArt": "5",
|
||||
@@ -85,16 +75,6 @@
|
||||
"duration": 0,
|
||||
"created": "2019-06-05T17:46:37.675917974+01:00"
|
||||
},
|
||||
{
|
||||
"id": "16",
|
||||
"coverArt": "16",
|
||||
"artistId": "5",
|
||||
"artist": "Swell Maps",
|
||||
"name": "Jane From Occupied Europe",
|
||||
"songCount": 16,
|
||||
"duration": 0,
|
||||
"created": "2019-04-30T16:48:48+01:00"
|
||||
},
|
||||
{
|
||||
"id": "19",
|
||||
"coverArt": "19",
|
||||
@@ -104,6 +84,26 @@
|
||||
"songCount": 15,
|
||||
"duration": 0,
|
||||
"created": "2019-04-30T16:48:30+01:00"
|
||||
},
|
||||
{
|
||||
"id": "21",
|
||||
"coverArt": "21",
|
||||
"artistId": "7",
|
||||
"artist": "Captain Beefheart & His Magic Band",
|
||||
"name": "Lick My Decals Off, Baby",
|
||||
"songCount": 15,
|
||||
"duration": 0,
|
||||
"created": "2019-06-10T19:26:30.944742894+01:00"
|
||||
},
|
||||
{
|
||||
"id": "16",
|
||||
"coverArt": "16",
|
||||
"artistId": "5",
|
||||
"artist": "Swell Maps",
|
||||
"name": "Jane From Occupied Europe",
|
||||
"songCount": 16,
|
||||
"duration": 0,
|
||||
"created": "2019-04-30T16:48:48+01:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user