Throttle getReplies so it isn't called that often.

This commit is contained in:
Roger Braun 2017-07-28 11:19:56 +02:00
parent da3b604d9d
commit 86773579ed

View file

@ -1,4 +1,4 @@
import { find, filter, sortBy } from 'lodash' import { find, filter, sortBy, throttle } from 'lodash'
import { statusType } from '../../modules/statuses.js' import { statusType } from '../../modules/statuses.js'
import Status from '../status/status.vue' import Status from '../status/status.vue'
@ -7,6 +7,21 @@ const sortAndFilterConversation = (conversation) => {
return sortBy(conversation, 'id') return sortBy(conversation, 'id')
} }
const getReplies = function (id) {
let res = []
id = Number(id)
let i
for (i = 0; i < this.conversation.length; i++) {
if (Number(this.conversation[i].in_reply_to_status_id) === id) {
res.push({
name: `#${i}`,
id: this.conversation[i].id
})
}
}
return res
}
const conversation = { const conversation = {
data () { data () {
return { return {
@ -58,20 +73,7 @@ const conversation = {
.then(() => this.fetchConversation()) .then(() => this.fetchConversation())
} }
}, },
getReplies (id) { getReplies: throttle(getReplies, 1000),
let res = []
id = Number(id)
let i
for (i = 0; i < this.conversation.length; i++) {
if (Number(this.conversation[i].in_reply_to_status_id) === id) {
res.push({
name: `#${i}`,
id: this.conversation[i].id
})
}
}
return res
},
focused (id) { focused (id) {
if (this.statusoid.retweeted_status) { if (this.statusoid.retweeted_status) {
return (id === this.statusoid.retweeted_status.id) return (id === this.statusoid.retweeted_status.id)