improve performance by caching pinned status ids into user object

This commit is contained in:
taehoon 2019-04-30 08:20:19 -04:00
parent 87de130ee5
commit 110c9d3b26
5 changed files with 29 additions and 15 deletions

View file

@ -42,9 +42,6 @@ const UserProfile = {
timeline () { timeline () {
return this.$store.state.statuses.timelines.user return this.$store.state.statuses.timelines.user
}, },
pinnedStatuses () {
return filter(this.timeline.statuses, { pinned: true })
},
favorites () { favorites () {
return this.$store.state.statuses.timelines.favorites return this.$store.state.statuses.timelines.favorites
}, },

View file

@ -5,13 +5,15 @@
<tab-switcher :renderOnlyFocused="true" ref="tabSwitcher"> <tab-switcher :renderOnlyFocused="true" ref="tabSwitcher">
<div :label="$t('user_card.statuses')" :disabled="!user.statuses_count"> <div :label="$t('user_card.statuses')" :disabled="!user.statuses_count">
<div class="timeline"> <div class="timeline">
<template v-for="statusId in user.pinnedStatuseIds">
<Conversation <Conversation
v-for="status in pinnedStatuses" v-if="timeline.statusesObject[statusId]"
class="status-fadein" class="status-fadein"
:key="status.id" :key="statusId"
:statusoid="status" :statusoid="timeline.statusesObject[statusId]"
:collapsable="true" :collapsable="true"
/> />
</template>
</div> </div>
<Timeline <Timeline
:count="user.statuses_count" :count="user.statuses_count"

View file

@ -424,7 +424,7 @@ export const mutations = {
newStatus.favoritedBy.push(user) newStatus.favoritedBy.push(user)
} }
}, },
setPinned (state, { status }) { setPinned (state, status) {
const newStatus = state.allStatusesObject[status.id] const newStatus = state.allStatusesObject[status.id]
newStatus.pinned = status.pinned newStatus.pinned = status.pinned
}, },
@ -543,11 +543,11 @@ const statuses = {
}, },
pinStatus ({ rootState, commit }, statusId) { pinStatus ({ rootState, commit }, statusId) {
return rootState.api.backendInteractor.pinOwnStatus(statusId) return rootState.api.backendInteractor.pinOwnStatus(statusId)
.then((status) => commit('setPinned', { status })) .then((status) => commit('setPinned', status))
}, },
unpinStatus ({ rootState, commit }, statusId) { unpinStatus ({ rootState, commit }, statusId) {
rootState.api.backendInteractor.unpinOwnStatus(statusId) rootState.api.backendInteractor.unpinOwnStatus(statusId)
.then((status) => commit('setPinned', { status })) .then((status) => commit('setPinned', status))
}, },
retweet ({ rootState, commit }, status) { retweet ({ rootState, commit }, status) {
// Optimistic retweeting... // Optimistic retweeting...

View file

@ -165,6 +165,15 @@ export const mutations = {
state.currentUser.muteIds.push(muteId) state.currentUser.muteIds.push(muteId)
} }
}, },
setPinned (state, status) {
const user = state.usersObject[status.user.id]
const index = user.pinnedStatuseIds.indexOf(status.id)
if (status.pinned && index === -1) {
user.pinnedStatuseIds.push(status.id)
} else if (!status.pinned && index !== -1) {
user.pinnedStatuseIds.splice(index, 1)
}
},
setUserForStatus (state, status) { setUserForStatus (state, status) {
status.user = state.usersObject[status.user.id] status.user = state.usersObject[status.user.id]
}, },
@ -318,13 +327,17 @@ const users = {
store.commit('addNewUsers', users) store.commit('addNewUsers', users)
store.commit('addNewUsers', retweetedUsers) store.commit('addNewUsers', retweetedUsers)
// Reconnect users to statuses
each(statuses, (status) => { each(statuses, (status) => {
// Reconnect users to statuses
store.commit('setUserForStatus', status) store.commit('setUserForStatus', status)
// Set pinned statuses to user
store.commit('setPinned', status)
}) })
// Reconnect users to retweets
each(compact(map(statuses, 'retweeted_status')), (status) => { each(compact(map(statuses, 'retweeted_status')), (status) => {
// Reconnect users to retweets
store.commit('setUserForStatus', status) store.commit('setUserForStatus', status)
// Set pinned retweets to user
store.commit('setPinned', status)
}) })
}, },
addNewNotifications (store, { notifications }) { addNewNotifications (store, { notifications }) {

View file

@ -131,6 +131,8 @@ export const parseUser = (data) => {
output.statuses_count = data.statuses_count output.statuses_count = data.statuses_count
output.friendIds = [] output.friendIds = []
output.followerIds = [] output.followerIds = []
output.pinnedStatuseIds = []
if (data.pleroma) { if (data.pleroma) {
output.follow_request_count = data.pleroma.follow_request_count output.follow_request_count = data.pleroma.follow_request_count
} }