Use find() instead of where() for song/albums views and add artists to song view

I think this makes things faster, but I may just be comparing to the scrobbles view which is terribly slow
This commit is contained in:
mitteneer 2025-03-28 10:11:07 -04:00
parent 05e9c05742
commit 0522a023b5
4 changed files with 22 additions and 4 deletions

View file

@ -10,6 +10,7 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
.include(.albumartists, .{ .select = .{.artist_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);
var album_view = try albums_view.append(.object);
@ -17,8 +18,8 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
var artist_infos = try album_view.put("artist_info", .array);
for (album.albumartists) |artist| {
var artist_info = try artist_infos.append(.object);
const artist_data = try jetzig.database.Query(.Artist).select(.{ .id, .name }).where(.{ .id = artist.artist_id }).all(request.repo);
for (artist_data) |ad| {
const artist_data = try jetzig.database.Query(.Artist).find(artist.artist_id).select(.{ .id, .name }).execute(request.repo);
if (artist_data) |ad| {
try artist_info.put("name", ad.name);
try artist_info.put("id", ad.id);
}