From 0a154de1f15e736b74fa12f54e361f9a2c5beb6d Mon Sep 17 00:00:00 2001 From: ThrRip Date: Sat, 23 Dec 2023 07:51:31 +0800 Subject: [PATCH] admin: Replace `map()` with `forEach()` if modifying ... the original array, for better performance --- packages/admin/pages/playlist.vue | 5 ++--- packages/home/app.vue | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/admin/pages/playlist.vue b/packages/admin/pages/playlist.vue index 247309f..47f04a5 100644 --- a/packages/admin/pages/playlist.vue +++ b/packages/admin/pages/playlist.vue @@ -137,13 +137,12 @@ async function viewPlaylistDataUpdate () { // Sort by song name or artist in alphabetical order if (viewPlaylistSortingColumn.value === 'name' || viewPlaylistSortingColumn.value === 'artist') { const pinyinPro = await import('pinyin-pro') - playlist.map((song) => { + playlist.forEach((song, index) => { // @ts-ignore - song[`${viewPlaylistSortingColumn.value}Pinyin`] = + playlist[index][`${viewPlaylistSortingColumn.value}Pinyin`] = // @ts-ignore pinyinPro.pinyin(song[viewPlaylistSortingColumn.value], { toneType: 'none', nonZh: 'consecutive' }) .replaceAll(' ', '') - return song }) playlist.sort((a, b) => { // @ts-ignore diff --git a/packages/home/app.vue b/packages/home/app.vue index 2937513..f410e1a 100644 --- a/packages/home/app.vue +++ b/packages/home/app.vue @@ -383,13 +383,12 @@ function viewPlaylistDataUpdate (tasks: Array<'shuffle' | 'sort'>) { // Sort by song name or artist in alphabetical order if (viewPlaylistSortingColumn.value === 'name' || viewPlaylistSortingColumn.value === 'artist') { const pinyinPro = await import('pinyin-pro') - playlist.map((song) => { + playlist.forEach((song, index) => { // @ts-ignore - song[`${viewPlaylistSortingColumn.value}Pinyin`] = + playlist[index][`${viewPlaylistSortingColumn.value}Pinyin`] = // @ts-ignore pinyinPro.pinyin(song[viewPlaylistSortingColumn.value], { toneType: 'none', nonZh: 'consecutive' }) .replaceAll(' ', '') - return song }) playlist.sort((a, b) => { // @ts-ignore