Update process_scrobbles.zig to fit new db
This commit is contained in:
parent
0537ef7db2
commit
64038079d8
1 changed files with 29 additions and 36 deletions
|
|
@ -54,55 +54,48 @@ pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig
|
||||||
// artists have an album of the same name, then
|
// artists have an album of the same name, then
|
||||||
// the IDs also depend on the hash of the artist
|
// the IDs also depend on the hash of the artist
|
||||||
// name. As far as I can tell, this is only an
|
// name. As far as I can tell, this is only an
|
||||||
// issue for Weezer.
|
// issue for Weezer and Peter Gabriel, but their
|
||||||
|
// albums go by unique names anyways.
|
||||||
|
|
||||||
// Artist: Artist hash. If two artists have the same name,
|
// Artist: Artist hash. If two artists have the same name,
|
||||||
// then a descriptive string can be provided to
|
// then a disambiguating string can be provided to
|
||||||
// differentiate after the fact, or in a rule.
|
// differentiate after the fact, or in a rule.
|
||||||
|
|
||||||
//var album_id: i32 = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(formed)));
|
//var album_id: i32 = @as(i32, @bitCast(std.hash.Fnv1a_32.hash(formed)));
|
||||||
//const song_id = (song_hash ^ artist_hash ^ album_hash);
|
//const song_id = (song_hash ^ artist_hash ^ album_hash);
|
||||||
|
|
||||||
// Inserts
|
var albumsong_id = try jetzig.database.Query(.Albumsong).findBy(.{ .album_id = album_id, .song_id = song_id }).select(.{.id}).execute(env.repo);
|
||||||
const album_insert = jetzig.database.Query(.Album).insert(.{ .id = album_id, .name = scrobble.album, .length = null });
|
var ins_album_id = try jetzig.database.Query(.Album).find(album_id).select(.{.id}).execute(env.repo);
|
||||||
const artist_insert = jetzig.database.Query(.Artist).insert(.{ .id = artist_id, .name = scrobble.artist, .descriptive_string = "" });
|
|
||||||
const song_insert = jetzig.database.Query(.Song).insert(.{ .id = song_id, .name = scrobble.track, .length = null, .hidden = false });
|
|
||||||
|
|
||||||
// Checks
|
var ins_artist_id = try jetzig.database.Query(.Artist).find(artist_id).select(.{.id}).execute(env.repo);
|
||||||
const album_check = try jetzig.database.Query(.Album).find(album_id).execute(env.repo);
|
if (ins_artist_id == null) ins_artist_id = try jetzig.database.Query(.Artist).insert(.{ .id = artist_id, .name = scrobble.artist, .disambiguation = null }).returning(.{.id}).execute(env.repo);
|
||||||
const artist_check = try jetzig.database.Query(.Artist).find(artist_id).execute(env.repo);
|
|
||||||
const song_check = try jetzig.database.Query(.Song).find(song_id).execute(env.repo);
|
|
||||||
|
|
||||||
// I think there must be a better way to do this next part
|
if (albumsong_id == null) {
|
||||||
// There are very few situations where artist_check is null
|
const ins_song_id: []const u8 =
|
||||||
// but song_check/album is not. Also yes, the order of these
|
jetzig.database.Query(.Song).insert(.{ .id = song_id, .name = scrobble.track, .length = null, .hidden = false }).returning(.{.id}).execute(env.repo) catch
|
||||||
// checks is weird, I didn't put a lot of thought into it
|
jetzig.database.Query(.Song).find(song_id).select(.{.id}).execute(env.repo);
|
||||||
var associative_table_flags: [3]bool = [3]bool{ true, true, true };
|
|
||||||
|
|
||||||
if (album_check == null) {
|
if (ins_album_id == null) ins_album_id = try jetzig.database.Query(.Album).insert(.{ .id = album_id, .name = scrobble.album, .length = null }).returning(.{.id}).execute(env.repo);
|
||||||
try env.repo.execute(album_insert);
|
|
||||||
try jetzig.database.Query(.Albumartist).insert(.{ .album_id = album_id, .artist_id = artist_id }).execute(env.repo);
|
albumsong_id = try jetzig.database.Query(.Albumsong).insert(.{ .song_id = ins_song_id, .album_id = ins_album_id }).execute(env.repo);
|
||||||
associative_table_flags[0] = false;
|
|
||||||
try jetzig.database.Query(.Albumsong).insert(.{ .album_id = album_id, .song_id = song_id }).execute(env.repo);
|
try jetzig.database.Query(.Albumsongartist).insert(.{ .albumsong_id = albumsong_id, .artist_id = ins_artist_id });
|
||||||
associative_table_flags[1] = false;
|
try jetzig.database.Query(.Artistalbum).insert(.{ .artist_id = ins_artist_id, .album_id = ins_album_id });
|
||||||
|
} else {
|
||||||
|
const ins_albumsongartist = try jetzig.database.Query(.Albumsongartist).findBy(.{ .albumsong_id = albumsong_id, .artist_id = ins_artist_id }).select(.{.id}).execute(env.repo);
|
||||||
|
if (ins_albumsongartist == null) try jetzig.database.Query(.Albumsongartist).insert(.{ .albumsong_id = albumsong_id, .artist_id = ins_artist_id }).execute(env.repo);
|
||||||
|
|
||||||
|
const ins_artistalbum = try jetzig.database.Query(.Artistalbum).findBy(.{ .albumsong_id = albumsong_id, .artist_id = ins_artist_id }).select(.{.id}).execute(env.repo);
|
||||||
|
if (ins_artistalbum == null) try jetzig.database.Query(.Artistalbum).insert(.{ .albumsong_id = albumsong_id, .artist_id = ins_artist_id }).execute(env.repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (artist_check == null) {
|
//if (ins_artist_id == null) {
|
||||||
try env.repo.execute(artist_insert);
|
// ins_artist_id = try jetzig.database.Query(.Artist).insert(.{ .id = artist_id, .name = scrobble.artist, .disambiguation = null }).returning(.{.id}).execute(env.repo);
|
||||||
if (associative_table_flags[0]) try jetzig.database.Query(.Albumartist).insert(.{ .album_id = album_id, .artist_id = artist_id }).execute(env.repo);
|
// try jetzig.database.Query(.Albumsongartist).insert(.{ .albumsong_id = albumsong_id, .artist_id = ins_artist_id });
|
||||||
try jetzig.database.Query(.Songartist).insert(.{ .song_id = song_id, .artist_id = artist_id }).execute(env.repo);
|
// try jetzig.database.Query(.Artistalbum).insert(.{ .artist_id = ins_artist_id, .album_id = ins_album_id });
|
||||||
associative_table_flags[2] = false;
|
//}
|
||||||
}
|
|
||||||
|
|
||||||
if (song_check == null) {
|
try jetzig.database.Query(.Scrobble).insert(.{ .albumsong_id = albumsong_id, .date = scrobble.date }).execute(env.repo);
|
||||||
try env.repo.execute(song_insert);
|
|
||||||
if (associative_table_flags[1]) try jetzig.database.Query(.Albumsong).insert(.{ .album_id = album_id, .song_id = song_id }).execute(env.repo);
|
|
||||||
if (associative_table_flags[2]) try jetzig.database.Query(.Songartist).insert(.{ .song_id = song_id, .artist_id = artist_id }).execute(env.repo);
|
|
||||||
}
|
|
||||||
|
|
||||||
const scr_id = try jetzig.database.Query(.Scrobble).insert(.{ .song_id = song_id, .album_id = album_id, .date = scrobble.date }).returning(.{.id}).execute(env.repo);
|
|
||||||
defer env.repo.free(scr_id);
|
|
||||||
try jetzig.database.Query(.Scrobbleartist).insert(.{ .scrobble_id = scr_id.?.id, .artist_id = artist_id }).execute(env.repo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue