From 566edf18189391559576af803f73c956951a3e91 Mon Sep 17 00:00:00 2001 From: mitteneer Date: Sat, 31 May 2025 15:48:30 -0400 Subject: [PATCH] Include artist(s) name in album GET view This also makes the entity_info struct very similar to the UnifiedResult struct, so we'll probably see a merge at some point. Would be nice if we used the fields from the entity_info result more commonly. --- src/app/views/albums/get.zmpl | 3 ++- src/app/views/artists/get.zmpl | 2 +- src/app/views/songs/get.zmpl | 2 +- src/queries.zig | 34 +++++++++++++++++++++++++--------- 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/app/views/albums/get.zmpl b/src/app/views/albums/get.zmpl index 22f99d8..7e089e7 100644 --- a/src/app/views/albums/get.zmpl +++ b/src/app/views/albums/get.zmpl @@ -9,7 +9,8 @@ @partial partials/header -

{{.album.name}}

+

{{.album.album_name}}

+

{{.album.artist_name}}

{{.album.scrobbles}} scrobbles ({{.album.rank}} place)
{{.album.song_num}} songs
@partial partials/firstlast_listens(firstlast: .firstlast) diff --git a/src/app/views/artists/get.zmpl b/src/app/views/artists/get.zmpl index 14976b5..9f1ff07 100644 --- a/src/app/views/artists/get.zmpl +++ b/src/app/views/artists/get.zmpl @@ -9,7 +9,7 @@ @partial partials/header -

{{.artist.name}}

+

{{.artist.artist_name}}

{{.artist.scrobbles}} scrobbles ({{.artist.rank}} place)
{{.artist.song_num}} songs
diff --git a/src/app/views/songs/get.zmpl b/src/app/views/songs/get.zmpl index 5b68145..e912930 100644 --- a/src/app/views/songs/get.zmpl +++ b/src/app/views/songs/get.zmpl @@ -9,7 +9,7 @@ @partial partials/header -

{{.song.name}}

+

{{.song.song_name}}

{{.song.scrobbles}} scrobbles ({{.song.rank}} place)
@partial partials/firstlast_listens(firstlast: .firstlast)

Yearly Performance

diff --git a/src/queries.zig b/src/queries.zig index a22b68e..194ef7f 100644 --- a/src/queries.zig +++ b/src/queries.zig @@ -17,7 +17,7 @@ pub fn entityQueryResult(request: *jetzig.Request, query: GeneratedQuery, args: if (query.query_type == .entity_info) { var out: *jetzig.Data.Value = try Data.object(); - const entity = try (try result.next()).?.to(struct { name: []const u8, id: i32, scrobbles: i64, album_num: ?i64 = null, song_num: ?i64 = null, rank: []const u8 }, .{ .dupe = true, .allocator = request.allocator, .map = .name }); + const entity = try (try result.next()).?.to(EntityInfoResult, .{ .dupe = true, .allocator = request.allocator, .map = .name }); try out.put("entity_info", entity); try result.drain(); return out.get("entity_info").?; @@ -74,6 +74,20 @@ const UnifiedResult = struct { date: ?[]const u8 = null, }; +const EntityInfoResult = struct { + album_name: ?[]const u8 = null, + album_id: ?i32 = null, + song_name: ?[]const u8 = null, + song_id: ?i32 = null, + artist_name: ?[]const u8 = null, + artist_id: ?i32 = null, + scrobbles: ?i64 = null, + date: ?[]const u8 = null, + rank: []const u8, + song_num: ?i64 = null, + album_num: ?i64 = null, +}; + pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery { return GeneratedQuery{ .entity = entity, @@ -301,28 +315,30 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery { .song => \\SELECT * FROM \\(SELECT *, TO_CHAR(ROW_NUMBER() OVER (ORDER BY scrobbles DESC),'FM99999th') AS rank FROM - \\(SELECT songs.name AS name, songs.id AS id, COUNT(scrobbles) AS scrobbles + \\(SELECT songs.name AS song_name, songs.id AS song_id, COUNT(scrobbles) AS scrobbles \\FROM albumsongs \\INNER JOIN songs ON albumsongs.song_id = songs.id \\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id \\GROUP BY songs.id)) - \\WHERE id = $1 + \\WHERE song_id = $1 , .album => - \\SELECT * FROM + \\SELECT album_name, t.album_id, artists.name AS artist_name, artists.id AS artist_id, song_num, scrobbles, rank FROM \\(SELECT *, TO_CHAR(ROW_NUMBER() OVER (ORDER BY scrobbles DESC),'FM9999th') AS rank FROM - \\(SELECT albums.name AS name, albums.id AS id, COUNT(DISTINCT songs.id) AS song_num, COUNT(scrobbles) AS scrobbles + \\(SELECT albums.name AS album_name, albums.id AS album_id, COUNT(DISTINCT songs.id) AS song_num, COUNT(scrobbles) AS scrobbles \\FROM albumsongs \\INNER JOIN albums ON albumsongs.album_id = albums.id \\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id \\INNER JOIN songs ON songs.id = albumsongs.song_id - \\GROUP BY albums.id)) - \\WHERE id = $1; + \\GROUP BY albums.id)) AS t + \\INNER JOIN artistalbums ON artistalbums.album_id = t.album_id + \\INNER JOIN artists ON artists.id = artistalbums.artist_id + \\WHERE t.album_id = $1 , .artist => \\SELECT * FROM \\(SELECT *, TO_CHAR(ROW_NUMBER() OVER (ORDER BY scrobbles DESC),'FM9999th') AS rank FROM - \\(SELECT artists.name AS name, artists.id AS id, COUNT(scrobbles) AS scrobbles, COUNT(DISTINCT albums.id) AS album_num, COUNT(DISTINCT songs.id) AS song_num + \\(SELECT artists.name AS artist_name, artists.id AS artist_id, COUNT(scrobbles) AS scrobbles, COUNT(DISTINCT albums.id) AS album_num, COUNT(DISTINCT songs.id) AS song_num \\FROM albumsongsartists \\INNER JOIN artists ON albumsongsartists.artist_id = artists.id \\INNER JOIN albumsongs ON albumsongsartists.albumsong_id = albumsongs.id @@ -330,7 +346,7 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery { \\INNER JOIN albums ON albums.id = albumsongs.album_id \\INNER JOIN songs ON songs.id = albumsongs.song_id \\GROUP BY artists.id)) - \\WHERE id = $1 + \\WHERE artist_id = $1 , },