Skip to content

Commit 03d8139

Browse files
committed
* Reduce array creation
1 parent a011a81 commit 03d8139

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/renderer/helpers/api/local.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,17 @@ export function parseLocalChannelHeader(channel, onlyIdNameThumbnail = false) {
738738
* @param {string} channelName
739739
*/
740740
export function parseLocalChannelVideos(videos, channelId, channelName) {
741-
return videos.map((video) => parseLocalListVideo(video, channelId, channelName))
741+
const parsedVideos = []
742+
743+
for (const video of videos) {
744+
// `BADGE_STYLE_TYPE_MEMBERS_ONLY` used for both `members only` and `members first` videos
745+
if (video.is(YTNodes.Video) && video.badges.some(badge => badge.style === 'BADGE_STYLE_TYPE_MEMBERS_ONLY')) {
746+
continue
747+
}
748+
parsedVideos.push(parseLocalListVideo(video, channelId, channelName))
749+
}
750+
751+
return parsedVideos
742752
}
743753

744754
/**

src/renderer/views/Channel/Channel.vue

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,6 @@ async function getChannelVideosLocal() {
10991099
}
11001100
11011101
latestVideos.value = parseLocalChannelVideos(videosTab.videos, id.value, channelName.value)
1102-
.filter(v => !v.isMemberOnly && !v.isMemberFirst)
11031102
videoContinuationData.value = videosTab.has_continuation ? videosTab : null
11041103
isElementListLoading.value = false
11051104
}
@@ -1146,7 +1145,6 @@ async function getChannelVideosLocalMore() {
11461145
11471146
latestVideos.value = latestVideos.value.concat(
11481147
parseLocalChannelVideos(continuation.videos, id.value, channelName.value)
1149-
.filter(v => !v.isMemberOnly && !v.isMemberFirst)
11501148
)
11511149
videoContinuationData.value = continuation.has_continuation ? continuation : null
11521150
}
@@ -1393,7 +1391,6 @@ async function getChannelLiveLocal() {
13931391
}
13941392
13951393
latestLive.value = parseLocalChannelVideos(videos, id.value, channelName.value)
1396-
.filter(v => !v.isMemberOnly && !v.isMemberFirst)
13971394
liveContinuationData.value = liveTab.has_continuation ? liveTab : null
13981395
isElementListLoading.value = false
13991396
@@ -1427,7 +1424,6 @@ async function getChannelLiveLocalMore() {
14271424
14281425
latestLive.value = latestLive.value.concat(
14291426
parseLocalChannelVideos(continuation.videos, id.value, channelName.value)
1430-
.filter(v => !v.isMemberOnly && !v.isMemberFirst)
14311427
)
14321428
liveContinuationData.value = continuation.has_continuation ? continuation : null
14331429
} catch (err) {
@@ -2052,18 +2048,18 @@ async function searchChannelLocal() {
20522048
contents = result.contents.contents
20532049
}
20542050
2055-
const results = contents
2051+
const results = []
2052+
contents
20562053
.filter(node => node.type === 'ItemSection')
20572054
.flatMap(itemSection => itemSection.contents)
2058-
.filter(item => item.type === 'Video' || (!hideChannelPlaylists.value && item.type === 'Playlist'))
2059-
.map(item => {
2055+
.forEach(item => {
20602056
if (item.type === 'Video') {
20612057
const video = parseLocalListVideo(item)
20622058
if (video.isMemberOnly || video.isMemberFirst) { return null }
20632059
2064-
return video
2065-
} else {
2066-
return parseLocalListPlaylist(item, id.value, channelName.value)
2060+
results.push(video)
2061+
} else if (!hideChannelPlaylists.value && item.type === 'Playlist') {
2062+
results.push(parseLocalListPlaylist(item, id.value, channelName.value))
20672063
}
20682064
})
20692065
.filter(item => item != null)

0 commit comments

Comments
 (0)