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:
parent
e22dc4c949
commit
cf84b4afdd
6 changed files with 22 additions and 18 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue