From 46c64f94982672336abe36b8350dbc9b0cddab4b Mon Sep 17 00:00:00 2001 From: Christopher Gurnee Date: Fri, 25 Mar 2022 15:10:18 +0000 Subject: [PATCH] Log time taken to load post/comments --- src/pages/thread/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pages/thread/index.js b/src/pages/thread/index.js index c8a3a4e..1398034 100644 --- a/src/pages/thread/index.js +++ b/src/pages/thread/index.js @@ -90,6 +90,7 @@ class Thread extends React.Component { componentDidMount () { const { subreddit, threadID, commentID } = this.props.match.params this.props.global.setLoading('Loading post...') + console.time('Load comments') // Get post from Reddit. Each code path below should end in either // setLoading() on success (if comments are still loading), or @@ -147,6 +148,7 @@ class Thread extends React.Component { this.props.global.setLoading('Loading comments from Pushshift...') }) .catch(error => { + console.timeEnd('Load comments') this.props.global.setError(error, error.helpUrl) this.stopLoading = true post.selftext = redditSelftext // restore it (after temporarily removing it above) @@ -172,17 +174,20 @@ class Thread extends React.Component { if (this.state.loadingComments) this.props.global.setLoading('Loading comments from Pushshift...') } else { + console.timeEnd('Load comments') this.props.global.setError({ message: '404 Post not found' }) this.stopLoading = true } } }) .catch(error => { + console.timeEnd('Load comments') this.props.global.setError(error, error.helpUrl) this.stopLoading = true }) } else { + console.timeEnd('Load comments') this.props.global.setError(error, error.helpUrl) this.stopLoading = true } @@ -245,6 +250,7 @@ class Thread extends React.Component { this.props.global.state.loadingMoreComments = 0 this.setState({reloadingComments: true}) this.props.global.setLoading('Loading more comments from Pushshift...') + console.time('Load comments') this.updateCurContig() this.getComments(loadingMoreComments, true) @@ -256,6 +262,7 @@ class Thread extends React.Component { if (commentID === undefined) { this.setState({loadingComments: true}) this.props.global.setLoading('Loading comments from Pushshift...') + console.time('Load comments') this.contigs.unshift({firstCreated: EARLIEST_CREATED}) this.setCurContig(0) this.getComments(this.props.global.maxComments) @@ -265,6 +272,7 @@ class Thread extends React.Component { this.commentIdAttempts.add(commentID) this.setState({reloadingComments: true}) this.props.global.setLoading('Loading comments from Pushshift...') + console.time('Load comments') let createdUtcNotFound // true if Reddit doesn't have the comment's created_utc getRedditComments([commentID]) .then(([comment]) => { @@ -286,6 +294,7 @@ class Thread extends React.Component { this.redditIdsToPushshift(comment) pushshiftCommentLookup.set(comment.id, comment) // so use the Reddit comment instead this.setCurContig(insertBefore - 1) // (this was the failed earlier attempt) + console.timeEnd('Load comments') this.props.global.setSuccess() this.setState({pushshiftCommentLookup, loadingComments: false, reloadingComments: false}) } @@ -385,6 +394,7 @@ class Thread extends React.Component { return comments.length }) .catch(error => { + console.timeEnd('Load comments') this.props.global.setError(error, error.helpUrl) this.stopLoading = true }) @@ -438,6 +448,7 @@ class Thread extends React.Component { this.getComments(newCommentCount - pushshiftComments, true, commentHint) else { + console.timeEnd('Load comments') this.props.global.setSuccess() this.setState({ pushshiftCommentLookup, @@ -453,6 +464,7 @@ class Thread extends React.Component { }) }) .catch(e => { + console.timeEnd('Load comments') this.props.global.setError(e, e.helpUrl) if (this.curContig().lastCreated === undefined) { this.contigs.splice(this.curContigIdx, 1)