Moved sorting to library.add()

This commit is contained in:
Djkato 2023-06-12 17:54:04 +02:00
parent 081cb68b3d
commit d1d8dcf98d
2 changed files with 3 additions and 8 deletions

View file

@ -49,7 +49,6 @@ class Euterpe extends Player.MusicPlayer {
new_song = this.queue.shift()! new_song = this.queue.shift()!
} else { } else {
let id_i = this.db.songs.length; let id_i = this.db.songs.length;
this.db.songs.sort((a, b) => a.id! - b.id!)
while (this.db.songs[--id_i].id! > this.current_song_id); while (this.db.songs[--id_i].id! > this.current_song_id);
const next_id = ++id_i; const next_id = ++id_i;
@ -81,7 +80,6 @@ class Euterpe extends Player.MusicPlayer {
new_song = this.queue.shift()! new_song = this.queue.shift()!
} else { } else {
let id_i = this.db.songs.length; let id_i = this.db.songs.length;
this.db.songs.sort((a, b) => a.id! - b.id!)
while (this.db.songs[--id_i].id! > this.current_song_id); while (this.db.songs[--id_i].id! > this.current_song_id);
let next_id = ++id_i let next_id = ++id_i
@ -111,7 +109,6 @@ class Euterpe extends Player.MusicPlayer {
new_song = this.queue.shift()! new_song = this.queue.shift()!
} else { } else {
let id_i = this.db.songs.length; let id_i = this.db.songs.length;
this.db.songs.sort((a, b) => a.id! - b.id!)
while (this.db.songs[--id_i].id! > this.current_song_id); while (this.db.songs[--id_i].id! > this.current_song_id);
let next_id = ++id_i; let next_id = ++id_i;
@ -134,7 +131,6 @@ class Euterpe extends Player.MusicPlayer {
new_song = this.queue.shift()! new_song = this.queue.shift()!
} else { } else {
let id_i = this.db.songs.length; let id_i = this.db.songs.length;
this.db.songs.sort((a, b) => a.id! - b.id!)
while (this.db.songs[--id_i].id! > this.current_song_id); while (this.db.songs[--id_i].id! > this.current_song_id);
const next_id = ++id_i; const next_id = ++id_i;
if (next_id == this.db.songs.length) throw new Error("Won't go past the last song") if (next_id == this.db.songs.length) throw new Error("Won't go past the last song")
@ -215,7 +211,6 @@ class Euterpe extends Player.MusicPlayer {
new_song = this.played_history.pop()! new_song = this.played_history.pop()!
} else { } else {
let id_i = 0; let id_i = 0;
this.db.songs.sort((a, b) => a.id! - b.id!)
while (this.db.songs[++id_i].id! < this.current_song_id); while (this.db.songs[++id_i].id! < this.current_song_id);
const next_id = --id_i; const next_id = --id_i;
@ -247,7 +242,6 @@ class Euterpe extends Player.MusicPlayer {
new_song = this.played_history.pop()! new_song = this.played_history.pop()!
} else { } else {
let id_i = -1; let id_i = -1;
this.db.songs.sort((a, b) => a.id! - b.id!)
while (this.db.songs[++id_i].id! < this.current_song_id); while (this.db.songs[++id_i].id! < this.current_song_id);
let next_id = --id_i; let next_id = --id_i;
@ -277,7 +271,6 @@ class Euterpe extends Player.MusicPlayer {
new_song = this.played_history.pop()! new_song = this.played_history.pop()!
} else { } else {
let id_i = 0; let id_i = 0;
this.db.songs.sort((a, b) => a.id! - b.id!)
while (this.db.songs[++id_i].id! < this.current_song_id); while (this.db.songs[++id_i].id! < this.current_song_id);
const next_id = -id_i; const next_id = -id_i;
@ -300,7 +293,6 @@ class Euterpe extends Player.MusicPlayer {
new_song = this.played_history.pop()! new_song = this.played_history.pop()!
} else { } else {
let id_i = 0; let id_i = 0;
this.db.songs.sort((a, b) => a.id! - b.id!)
while (this.db.songs[++id_i].id! < this.current_song_id); while (this.db.songs[++id_i].id! < this.current_song_id);
let next_id = -id_i; let next_id = -id_i;

View file

@ -205,6 +205,9 @@ class DB {
} }
} }
} }
this.songs.sort((a, b) => a.id! - b.id!)
this.collections.sort((a, b) => a.id! - b.id!)
this.artists.sort((a, b) => a.id! - b.id!)
} }
} }
// const db = new DB // const db = new DB