Skip to content

Commit 5b999a8

Browse files
authored
Merge pull request #10673 from Stypox/transaction-too-large
Fix transaction too large in channel tab fragments
2 parents 4825318 + 495c985 commit 5b999a8

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelTabFragment.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.schabi.newpipe.fragments.list.channel;
22

33
import android.os.Bundle;
4+
import android.util.Log;
45
import android.view.LayoutInflater;
56
import android.view.View;
67
import android.view.ViewGroup;
@@ -14,7 +15,9 @@
1415
import org.schabi.newpipe.extractor.InfoItem;
1516
import org.schabi.newpipe.extractor.ListExtractor;
1617
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabInfo;
18+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1719
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
20+
import org.schabi.newpipe.extractor.linkhandler.ReadyChannelTabListLinkHandler;
1821
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1922
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
2023
import org.schabi.newpipe.fragments.list.playlist.PlaylistControlViewHolder;
@@ -114,6 +117,27 @@ public void setTitle(final String title) {
114117
public void handleResult(@NonNull final ChannelTabInfo result) {
115118
super.handleResult(result);
116119

120+
// FIXME this is a really hacky workaround, to avoid storing useless data in the fragment
121+
// state. The problem is, `ReadyChannelTabListLinkHandler` might contain raw JSON data that
122+
// uses a lot of memory (e.g. ~800KB for YouTube). While 800KB doesn't seem much, if
123+
// you combine just a couple of channel tab fragments you easily go over the 1MB
124+
// save&restore transaction limit, and get `TransactionTooLargeException`s. A proper
125+
// solution would require rethinking about `ReadyChannelTabListLinkHandler`s.
126+
if (tabHandler instanceof ReadyChannelTabListLinkHandler) {
127+
try {
128+
// once `handleResult` is called, the parsed data was already saved to cache, so
129+
// we can discard any raw data in ReadyChannelTabListLinkHandler and create a
130+
// link handler with identical properties, but without any raw data
131+
tabHandler = result.getService()
132+
.getChannelTabLHFactory()
133+
.fromQuery(tabHandler.getId(), tabHandler.getContentFilters(),
134+
tabHandler.getSortFilter());
135+
} catch (final ParsingException e) {
136+
// silently ignore the error, as the app can continue to function normally
137+
Log.w(TAG, "Could not recreate channel tab handler", e);
138+
}
139+
}
140+
117141
if (playlistControlBinding != null) {
118142
// PlaylistControls should be visible only if there is some item in
119143
// infoListAdapter other than header

0 commit comments

Comments
 (0)