From 480a1ba253d49d4df36fbc64192e1260fc51a181 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 8 Mar 2017 17:59:12 +0100 Subject: Use cache to quickly access users. --- src/modules/users.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index 31731880..dc910c91 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -3,9 +3,9 @@ import { compact, map, each, find, merge } from 'lodash' import { set } from 'vue' // TODO: Unify with mergeOrAdd in statuses.js -export const mergeOrAdd = (arr, item) => { +export const mergeOrAdd = (arr, obj, item) => { if (!item) { return false } - const oldItem = find(arr, {id: item.id}) + const oldItem = obj[item.id] if (oldItem) { // We already have this, so only merge the new info. merge(oldItem, item) @@ -13,6 +13,7 @@ export const mergeOrAdd = (arr, item) => { } else { // This is a new item, prepare it arr.push(item) + obj[item.id] = item return {item, new: true} } } @@ -32,7 +33,7 @@ export const mutations = { state.loggingIn = false }, addNewUsers (state, users) { - each(users, (user) => mergeOrAdd(state.users, user)) + each(users, (user) => mergeOrAdd(state.users, state.usersObject, user)) }, setUserForStatus (state, status) { status.user = find(state.users, status.user) @@ -42,7 +43,8 @@ export const mutations = { export const defaultState = { currentUser: false, loggingIn: false, - users: [] + users: [], + usersObject: {} } const users = { -- cgit v1.2.3-70-g09d2 From 5699872bb5e05b5dc576c75cac2c79b7ece3f2ac Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 8 Mar 2017 18:04:21 +0100 Subject: Use user cache in users module. --- src/modules/users.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/modules/users.js') diff --git a/src/modules/users.js b/src/modules/users.js index dc910c91..9367ec68 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -1,5 +1,5 @@ import backendInteractorService from '../services/backend_interactor_service/backend_interactor_service.js' -import { compact, map, each, find, merge } from 'lodash' +import { compact, map, each, merge } from 'lodash' import { set } from 'vue' // TODO: Unify with mergeOrAdd in statuses.js @@ -20,7 +20,7 @@ export const mergeOrAdd = (arr, obj, item) => { export const mutations = { setMuted (state, { user: {id}, muted }) { - const user = find(state.users, {id}) + const user = state.usersObject[id] set(user, 'muted', muted) }, setCurrentUser (state, user) { @@ -36,7 +36,7 @@ export const mutations = { each(users, (user) => mergeOrAdd(state.users, state.usersObject, user)) }, setUserForStatus (state, status) { - status.user = find(state.users, status.user) + status.user = state.usersObject[status.user.id] } } -- cgit v1.2.3-70-g09d2