From 110c9d3b26e3871c8fc8157458be201ed4316d49 Mon Sep 17 00:00:00 2001
From: taehoon
Date: Tue, 30 Apr 2019 08:20:19 -0400
Subject: [PATCH] improve performance by caching pinned status ids into user
object
---
src/components/user_profile/user_profile.js | 3 ---
src/components/user_profile/user_profile.vue | 16 +++++++++-------
src/modules/statuses.js | 6 +++---
src/modules/users.js | 17 +++++++++++++++--
.../entity_normalizer.service.js | 2 ++
5 files changed, 29 insertions(+), 15 deletions(-)
diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js
index 176ec228..8d660780 100644
--- a/src/components/user_profile/user_profile.js
+++ b/src/components/user_profile/user_profile.js
@@ -42,9 +42,6 @@ const UserProfile = {
timeline () {
return this.$store.state.statuses.timelines.user
},
- pinnedStatuses () {
- return filter(this.timeline.statuses, { pinned: true })
- },
favorites () {
return this.$store.state.statuses.timelines.favorites
},
diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue
index 1e104403..36d75b9e 100644
--- a/src/components/user_profile/user_profile.vue
+++ b/src/components/user_profile/user_profile.vue
@@ -5,13 +5,15 @@
-
+
+
+
commit('setPinned', { status }))
+ .then((status) => commit('setPinned', status))
},
unpinStatus ({ rootState, commit }, statusId) {
rootState.api.backendInteractor.unpinOwnStatus(statusId)
- .then((status) => commit('setPinned', { status }))
+ .then((status) => commit('setPinned', status))
},
retweet ({ rootState, commit }, status) {
// Optimistic retweeting...
diff --git a/src/modules/users.js b/src/modules/users.js
index adcab233..e72a657c 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -165,6 +165,15 @@ export const mutations = {
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) {
status.user = state.usersObject[status.user.id]
},
@@ -318,13 +327,17 @@ const users = {
store.commit('addNewUsers', users)
store.commit('addNewUsers', retweetedUsers)
- // Reconnect users to statuses
each(statuses, (status) => {
+ // Reconnect users to statuses
store.commit('setUserForStatus', status)
+ // Set pinned statuses to user
+ store.commit('setPinned', status)
})
- // Reconnect users to retweets
each(compact(map(statuses, 'retweeted_status')), (status) => {
+ // Reconnect users to retweets
store.commit('setUserForStatus', status)
+ // Set pinned retweets to user
+ store.commit('setPinned', status)
})
},
addNewNotifications (store, { notifications }) {
diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js
index 5b8ad8a4..e3d1646a 100644
--- a/src/services/entity_normalizer/entity_normalizer.service.js
+++ b/src/services/entity_normalizer/entity_normalizer.service.js
@@ -131,6 +131,8 @@ export const parseUser = (data) => {
output.statuses_count = data.statuses_count
output.friendIds = []
output.followerIds = []
+ output.pinnedStatuseIds = []
+
if (data.pleroma) {
output.follow_request_count = data.pleroma.follow_request_count
}