Skip to content

Commit e9992bf

Browse files
committed
YoutubeMusicSearchExtractor: Add caching to improve performance
1 parent bce125c commit e9992bf

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMusicSearchExtractor.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@
3434
import java.nio.charset.StandardCharsets;
3535
import java.util.Collections;
3636
import java.util.List;
37-
import java.util.stream.Collectors;
3837
import java.util.Objects;
38+
import java.util.stream.Collectors;
3939

4040
import javax.annotation.Nonnull;
4141
import javax.annotation.Nullable;
4242

4343
public class YoutubeMusicSearchExtractor extends SearchExtractor {
4444
private JsonObject initialData;
4545

46+
private List<JsonObject> cachedItemSectionRendererContents;
47+
4648
public YoutubeMusicSearchExtractor(final StreamingService service,
4749
final SearchQueryHandler linkHandler) {
4850
super(service, linkHandler);
@@ -116,7 +118,11 @@ public void onFetchPage(@Nonnull final Downloader downloader)
116118
}
117119

118120
private List<JsonObject> getItemSectionRendererContents() {
119-
return initialData
121+
if (cachedItemSectionRendererContents != null) {
122+
return cachedItemSectionRendererContents;
123+
}
124+
125+
cachedItemSectionRendererContents = initialData
120126
.getObject("contents")
121127
.getObject("tabbedSearchResultsRenderer")
122128
.getArray("tabs")
@@ -134,6 +140,7 @@ private List<JsonObject> getItemSectionRendererContents() {
134140
.getArray("contents")
135141
.getObject(0))
136142
.collect(Collectors.toList());
143+
return cachedItemSectionRendererContents;
137144
}
138145

139146
@Nonnull

0 commit comments

Comments
 (0)