Much faster load time for large threads

This commit is contained in:
Jubbeart 2018-02-17 22:51:38 +01:00
parent 2f2a65e60b
commit abcee0450c
3 changed files with 43 additions and 49 deletions

View file

@ -54,8 +54,6 @@ add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
```
In the same file you also want to change `gzip on` to `gzip off` (read more [here](https://github.com/h5bp/server-configs-nginx/issues/72)).
## Nginx server config
Copy the ssl config and create a soft link. Create folder for logs and also remove the default config
```

View file

@ -1,4 +1,4 @@
import { json, toBase10, toBase36, chunk, flatten } from 'utils'
import { json, toBase10, toBase36 } from 'utils'
const baseURL = 'https://elastic.pushshift.io'
const postURL = `${baseURL}/rs/submissions/_search?source=`
@ -24,52 +24,48 @@ export const getPost = threadID => {
)
}
export const getComments = threadID => (
fetch(`https://api.pushshift.io/reddit/comment/search?link_id=${threadID}&limit=10000`)
.then(json)
.then(data => data.data)
.then(comments => {
comments.forEach(comment => {
comment.link_id = comment.link_id.split('_')[1]
comment.parent_id = comment.parent_id.split('_')[1]
})
return comments
})
)
// export const getComments = threadID => (
// fetch(`https://api.pushshift.io/reddit/comment/search?link_id=${threadID}&limit=10000`)
// .then(json)
// .then(data => data.data)
// .then(comments => {
// comments.forEach(comment => {
// comment.link_id = comment.link_id.split('_')[1]
// comment.parent_id = comment.parent_id.split('_')[1]
// })
// return comments
// })
// )
// export const getComments = threadID => {
// const elasticQuery = {
// query: {
// match: {
// link_id: toBase10(threadID),
// },
// },
// size: 10000,
// // _source: [
// // 'author', 'body', 'created_utc', 'parent_id', 'score', 'subreddit', 'link_id',
// // ],
// }
export const getComments = threadID => {
const elasticQuery = {
query: {
match: {
link_id: toBase10(threadID),
},
},
size: 10000,
_source: [
'author', 'body', 'created_utc', 'parent_id', 'score', 'subreddit', 'link_id',
],
}
// return (
// fetch(commentURL + JSON.stringify(elasticQuery))
// .then(json)
// .then(jsonData => jsonData.hits.hits)
// .then(comments => comments.map(comment => {
// comment._source.id = toBase36(comment._id)
// comment._source.link_id = toBase36(comment._source.link_id)
return (
fetch(commentURL + JSON.stringify(elasticQuery))
.then(json)
.then(jsonData => jsonData.hits.hits)
.then(comments => comments.map(comment => {
comment._source.id = toBase36(comment._id)
comment._source.link_id = toBase36(comment._source.link_id)
// // Missing parent id === direct reply to thread
// if (!comment._source.parent_id) {
// comment._source.parent_id = threadID
// } else {
// comment._source.parent_id = toBase36(comment._source.parent_id)
// }
// Missing parent id === direct reply to thread
if (!comment._source.parent_id) {
comment._source.parent_id = threadID
} else {
comment._source.parent_id = toBase36(comment._source.parent_id)
}
// if (comment._source.id === 'dmrxgic') {
// console.log(JSON.stringify(comment._source))
// }
// return comment._source
// }))
// )
// }
return comment._source
}))
)
}

View file

@ -1,6 +1,6 @@
import { json } from 'utils'
const baseURL = 'http://localhost:9000/api'
const baseURL = 'https://removeddit.com/api'
export const getRemovedThreadIDs = (subreddit = '', page = 1) => (
fetch(`${baseURL}/threads?subreddit=${subreddit}&page=${page - 1}`)