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:
infinite-persistence 2021-11-17 16:05:50 +08:00
parent 5204bb366e
commit 91f1f588e6
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -214,8 +214,11 @@ export const selectTopLevelCommentsForUri = createCachedSelector(
...Object.values(filterCommentsDepOnList), ...Object.values(filterCommentsDepOnList),
(uri, maxCount = -1, byClaimId, claimId, ...filterInputs) => { (uri, maxCount = -1, byClaimId, claimId, ...filterInputs) => {
const comments = byClaimId && byClaimId[claimId]; const comments = byClaimId && byClaimId[claimId];
const filtered = filterComments(comments, claimId, filterInputs); if (comments) {
return maxCount > 0 ? filtered.slice(0, maxCount) : filtered; return filterComments(maxCount > 0 ? comments.slice(0, maxCount) : comments, claimId, filterInputs);
} else {
return [];
}
} }
)((state, uri, maxCount = -1) => `${String(uri)}:${maxCount}`); )((state, uri, maxCount = -1) => `${String(uri)}:${maxCount}`);