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:
parent
05e9c05742
commit
0522a023b5
4 changed files with 22 additions and 4 deletions
|
|
@ -10,6 +10,7 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
|
||||||
.include(.albumartists, .{ .select = .{.artist_id} })
|
.include(.albumartists, .{ .select = .{.artist_id} })
|
||||||
.orderBy(.{ .name = .asc });
|
.orderBy(.{ .name = .asc });
|
||||||
const albums = try request.repo.all(query);
|
const albums = try request.repo.all(query);
|
||||||
|
|
||||||
for (albums) |album| {
|
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 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);
|
var artist_infos = try album_view.put("artist_info", .array);
|
||||||
for (album.albumartists) |artist| {
|
for (album.albumartists) |artist| {
|
||||||
var artist_info = try artist_infos.append(.object);
|
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);
|
const artist_data = try jetzig.database.Query(.Artist).find(artist.artist_id).select(.{ .id, .name }).execute(request.repo);
|
||||||
for (artist_data) |ad| {
|
if (artist_data) |ad| {
|
||||||
try artist_info.put("name", ad.name);
|
try artist_info.put("name", ad.name);
|
||||||
try artist_info.put("id", ad.id);
|
try artist_info.put("id", ad.id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ const jetzig = @import("jetzig");
|
||||||
pub fn index(request: *jetzig.Request) !jetzig.View {
|
pub fn index(request: *jetzig.Request) !jetzig.View {
|
||||||
var root = try request.data(.object);
|
var root = try request.data(.object);
|
||||||
var scrobbles_view = try root.put("scrobbles", .array);
|
var scrobbles_view = try root.put("scrobbles", .array);
|
||||||
const query = jetzig.database.Query(.Scrobble).select(.{.date})
|
const query = jetzig.database.Query(.Scrobble).select(.{ .id, .date })
|
||||||
.include(.song, .{ .select = .{ .id, .name } })
|
.include(.song, .{ .select = .{ .id, .name } })
|
||||||
.include(.album, .{ .select = .{ .id, .name } })
|
.include(.album, .{ .select = .{ .id, .name } })
|
||||||
.include(.scrobbleartists, .{ .select = .{.artist_id} })
|
.include(.scrobbleartists, .{ .select = .{.artist_id} })
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,20 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
|
||||||
.include(.songartists, .{ .select = .{.artist_id} })
|
.include(.songartists, .{ .select = .{.artist_id} })
|
||||||
.orderBy(.{ .name = .asc });
|
.orderBy(.{ .name = .asc });
|
||||||
const songs = try request.repo.all(query);
|
const songs = try request.repo.all(query);
|
||||||
|
|
||||||
for (songs) |song| {
|
for (songs) |song| {
|
||||||
const scrobbles = try jetzig.database.Query(.Scrobble).where(.{ .song_id = song.id }).count().execute(request.repo);
|
const scrobbles = try jetzig.database.Query(.Scrobble).where(.{ .song_id = song.id }).count().execute(request.repo);
|
||||||
var song_view = try songs_view.append(.object);
|
var song_view = try songs_view.append(.object);
|
||||||
|
|
||||||
|
var artist_infos = try song_view.put("artist_info", .array);
|
||||||
|
for (song.songartists) |artist| {
|
||||||
|
var artist_info = try artist_infos.append(.object);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
try song_view.put("name", song.name);
|
try song_view.put("name", song.name);
|
||||||
try song_view.put("url", song.id);
|
try song_view.put("url", song.id);
|
||||||
try song_view.put("scrobbles", scrobbles);
|
try song_view.put("scrobbles", scrobbles);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
|
<th>Artists(s)</th>
|
||||||
<th>Scrobbles</th>
|
<th>Scrobbles</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
@ -17,7 +18,12 @@
|
||||||
@for (.songs) |song| {
|
@for (.songs) |song| {
|
||||||
<tr>
|
<tr>
|
||||||
<td class=cell><a href="/songs/{{song.url}}">{{song.name}}</a></td>
|
<td class=cell><a href="/songs/{{song.url}}">{{song.name}}</a></td>
|
||||||
<td>{{song.scrobbles}}</td>
|
<td class=cell>
|
||||||
|
@for (song.get("artist_info").?) |ai| {
|
||||||
|
<a href="/artists/{{ai.id}}">{{ai.name}}</a>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
|
<td class=cell>{{song.scrobbles}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue