Skip to content

Commit

Permalink
admin: Replace some() with find()
Browse files Browse the repository at this point in the history
... for better performance
  • Loading branch information
ThrRip committed Dec 23, 2023
1 parent 1969c01 commit ee59c7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions packages/admin/components/PlaylistList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
v-if="props.type === 'changes' && props.data.find(unmodified => unmodified.$id === song.$id)?.name !== song.name"
class="flex flex-row gap-x-1.5"
>
<span v-if="props.data.some(unmodified => unmodified.$id === song.$id)" class="px-2.5 py-0.5 rounded-lg bg-pink-l/75">
<span v-if="props.data.find(unmodified => unmodified.$id === song.$id)" class="px-2.5 py-0.5 rounded-lg bg-pink-l/75">
<s>{{ props.data.find(unmodified => unmodified.$id === song.$id)?.name }}</s>
</span>
<span v-if="song.name" class="px-2.5 py-0.5 rounded-lg bg-blue-l/50">
Expand Down Expand Up @@ -301,7 +301,7 @@
v-if="props.type === 'changes' && props.data.find(unmodified => unmodified.$id === song.$id)?.artist !== song.artist"
class="flex flex-row gap-x-1.5"
>
<span v-if="props.data.some(unmodified => unmodified.$id === song.$id)" class="px-2.5 py-0.5 rounded-lg bg-pink-l/75">
<span v-if="props.data.find(unmodified => unmodified.$id === song.$id)" class="px-2.5 py-0.5 rounded-lg bg-pink-l/75">
<s>{{ props.data.find(unmodified => unmodified.$id === song.$id)?.artist }}</s>
</span>
<span v-if="song.artist" class="px-2.5 py-0.5 rounded-lg bg-blue-l/50">
Expand Down Expand Up @@ -414,7 +414,7 @@
v-if="props.type === 'changes' && props.data.find(unmodified => unmodified.$id === song.$id)?.language !== song.language"
class="flex flex-col gap-y-1 py-0.5"
>
<span v-if="props.data.some(unmodified => unmodified.$id === song.$id)" class="px-2.5 py-0.5 rounded-lg bg-pink-l/75">
<span v-if="props.data.find(unmodified => unmodified.$id === song.$id)" class="px-2.5 py-0.5 rounded-lg bg-pink-l/75">
<s>{{ props.data.find(unmodified => unmodified.$id === song.$id)?.language }}</s>
</span>
<span v-if="song.language" class="px-2.5 py-0.5 rounded-lg bg-blue-l/50">
Expand Down
12 changes: 6 additions & 6 deletions packages/admin/pages/playlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const viewPlaylistDataWithChanges = computed<Playlist>(() => {
if (Object.keys(changes).length === 1 && Object.keys(changes)[0] === '$id') {
playlist.splice(playlist.findIndex(song => song.$id === changes.$id), 1)
} else
if (playlist.some(song => song.$id === changes.$id)) {
if (playlist.find(song => song.$id === changes.$id)) {
playlist[playlist.findIndex(song => song.$id === changes.$id)] = changes
} else {
playlist.push(changes)
Expand Down Expand Up @@ -187,7 +187,7 @@ function viewPlaylistStageChanges (changes: Song) {

// New song
// @ts-ignore
if (!backendPlaylist.value.some(song => song.$id === changes.$id) && Object.keys(changes).length === changesFieldsAccepted.size) {
if (!backendPlaylist.value.find(song => song.$id === changes.$id) && Object.keys(changes).length === changesFieldsAccepted.size) {
const changesFields: Set<string> = new Set(Object.keys(changes))
let changesFieldsFulfilled: boolean = true
changesFieldsAccepted.forEach((field) => {
Expand All @@ -200,7 +200,7 @@ function viewPlaylistStageChanges (changes: Song) {
} else

// Modify song
if (viewPlaylistData.value.some(song => song.$id === changes.$id) && Object.keys(changes).length > 1) {
if (viewPlaylistData.value.find(song => song.$id === changes.$id) && Object.keys(changes).length > 1) {
// @ts-ignore
const song = viewPlaylistChangesData.value.find(_ => _.$id === changes.$id) ?? backendPlaylist.value.find(_ => _.$id === changes.$id)
let changesValid = false
Expand All @@ -225,16 +225,16 @@ function viewPlaylistStageChanges (changes: Song) {

// Delete song
if (
viewPlaylistData.value.some(song => song.$id === changes.$id) &&
viewPlaylistData.value.find(song => song.$id === changes.$id) &&
Object.keys(changes).length === 1 &&
changes.$id
) {
if (viewPlaylistChangesData.value.some(song => song.$id === changes.$id)) {
if (viewPlaylistChangesData.value.find(song => song.$id === changes.$id)) {
viewPlaylistChangesData.value.splice(viewPlaylistChangesData.value.findIndex(song => song.$id === changes.$id), 1)
}
// If the song is not published yet, do not create a change
// @ts-ignore
if (backendPlaylist.value.some(song => song.$id === changes.$id)) {
if (backendPlaylist.value.find(song => song.$id === changes.$id)) {
viewPlaylistChangesData.value.push(changes)
}
}
Expand Down

0 comments on commit ee59c7b

Please sign in to comment.