Skip to content

Commit ed57fcf

Browse files
committed
perf(sources): fetch video sources and collections at the same time
1 parent c90f6cd commit ed57fcf

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

background/sources/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,15 @@ const sources = {
6161
}));
6262
};
6363

64-
// First, get videos directly from where they're hosted,
64+
const [sourceResults, colResults] = await Promise.all([
65+
fetchEnabledSources('videos', true),
66+
fetchEnabledSources('collections', false)
67+
]);
68+
69+
// First, collect videos directly from where they're hosted,
6570
// in case any of them are included in collection sites.
66-
const sourceResults = await fetchEnabledSources('videos', true);
71+
// And if they are, that's one less API request we have to make to
72+
// get that video's metadata.
6773
const videos = [].concat(...sourceResults.map((result) => {
6874
result.videos.forEach((video, i) => {
6975
video.source = result.source;
@@ -77,7 +83,6 @@ const sources = {
7783
cachedVideos.push(video.url, video, true);
7884
});
7985

80-
const colResults = await fetchEnabledSources('collections', false);
8186
const colVideos = [].concat(...colResults.map((result) => {
8287
result.videos.forEach((video, i) => {
8388
const col = video.col || {};

0 commit comments

Comments
 (0)