Slice the comments before filtering to avoid going through everything.
For the case of livestreams, the comments are added incrementally via websocket. The selector returns everything, which grows as a user watches the livestream. We could even make it a bit more efficient by passing in `maxCount` to `filterComments`, and do a `for` loop there, but decided to keep things readable by not changing the `filter` usage.
This commit is contained in:
parent
5204bb366e
commit
91f1f588e6
1 changed files with 5 additions and 2 deletions
|
@ -214,8 +214,11 @@ export const selectTopLevelCommentsForUri = createCachedSelector(
|
|||
...Object.values(filterCommentsDepOnList),
|
||||
(uri, maxCount = -1, byClaimId, claimId, ...filterInputs) => {
|
||||
const comments = byClaimId && byClaimId[claimId];
|
||||
const filtered = filterComments(comments, claimId, filterInputs);
|
||||
return maxCount > 0 ? filtered.slice(0, maxCount) : filtered;
|
||||
if (comments) {
|
||||
return filterComments(maxCount > 0 ? comments.slice(0, maxCount) : comments, claimId, filterInputs);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
)((state, uri, maxCount = -1) => `${String(uri)}:${maxCount}`);
|
||||
|
||||
|
|
Loading…
Reference in a new issue