Skip to content

Commit

Permalink
admin: Replace map() with forEach() if modifying
Browse files Browse the repository at this point in the history
... the original array, for better performance
  • Loading branch information
ThrRip committed Dec 23, 2023
1 parent ee59c7b commit 0a154de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions packages/admin/pages/playlist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions packages/home/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a154de

Please sign in to comment.