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

@ -7,17 +7,18 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
var artists_view = try root.put("artists", .array);
const query = jetzig.database.Query(.Artist)
.select(.{ .id, .name })
.include(.scrobbleartists, .{ .select = .{.id} })
.orderBy(.{ .name = .asc });
const artists = try request.repo.all(query);
for (artists) |artist| {
const scrobbles = try jetzig.database.Query(.Scrobbleartist)
.where(.{ .artist_id = artist.id })
.count()
.execute(request.repo);
//const scrobbles = try jetzig.database.Query(.Scrobbleartist)
// .where(.{ .artist_id = artist.id })
// .count()
// .execute(request.repo);
var artist_view = try artists_view.append(.object);
try artist_view.put("name", artist.name);
try artist_view.put("url", artist.id);
try artist_view.put("scrobbles", scrobbles);
try artist_view.put("scrobbles", (artist.scrobbleartists).len);
}
return request.render(.ok);