Remove unnecessary db search for scrobbles

I forgot I made scrobbles owned by their respective songs/albums/artists, so I can just query that instead
This commit is contained in:
mitteneer 2025-03-28 13:09:51 -04:00
parent e22dc4c949
commit cf84b4afdd
6 changed files with 22 additions and 18 deletions

View file

@ -8,14 +8,15 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
const query = jetzig.database.Query(.Album)
.select(.{ .id, .name })
.include(.albumartists, .{ .select = .{.artist_id} })
.include(.scrobbles, .{ .select = .{.id} })
.orderBy(.{ .name = .asc });
const albums = try request.repo.all(query);
for (albums) |album| {
const scrobbles = try jetzig.database.Query(.Scrobble)
.where(.{ .album_id = album.id })
.count()
.execute(request.repo);
//const scrobbles = try jetzig.database.Query(.Scrobble)
// .where(.{ .album_id = album.id })
// .count()
// .execute(request.repo);
var album_view = try albums_view.append(.object);
var artist_infos = try album_view.put("artist_info", .array);
@ -31,7 +32,8 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
try album_view.put("name", album.name);
try album_view.put("url", album.id);
try album_view.put("scrobbles", scrobbles);
//try album_view.put("scrobbles", scrobbles);
try album_view.put("scrobbles", (album.scrobbles).len);
}
return request.render(.ok);
}