Skip to content

Commit ef0d69f

Browse files
authored
Various performance improvements to the store (#5522)
1 parent a261a0e commit ef0d69f

File tree

3 files changed

+17
-37
lines changed

3 files changed

+17
-37
lines changed

src/renderer/store/modules/profiles.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ const actions = {
9191
commit('setProfileList', profiles)
9292
},
9393

94-
async batchUpdateSubscriptionDetails({ getters, dispatch }, channels) {
94+
async batchUpdateSubscriptionDetails({ dispatch, state }, channels) {
9595
if (channels.length === 0) { return }
9696

97-
const profileList = getters.getProfileList
97+
const profileList = state.profileList
9898

9999
for (const profile of profileList) {
100100
const currentProfileCopy = deepCopy(profile)
@@ -128,9 +128,9 @@ const actions = {
128128
}
129129
},
130130

131-
async updateSubscriptionDetails({ getters, dispatch }, { channelThumbnailUrl, channelName, channelId }) {
131+
async updateSubscriptionDetails({ dispatch, state }, { channelThumbnailUrl, channelName, channelId }) {
132132
const thumbnail = channelThumbnailUrl?.replace(/=s\d*/, '=s176') ?? null // change thumbnail size if different
133-
const profileList = getters.getProfileList
133+
const profileList = state.profileList
134134
for (const profile of profileList) {
135135
const currentProfileCopy = deepCopy(profile)
136136
const channel = currentProfileCopy.subscriptions.find((channel) => {

src/renderer/store/modules/settings.js

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,14 @@ const stateWithSideEffects = {
385385
await Promise.allSettled(loadPromises)
386386

387387
i18n.locale = targetLocale
388-
await dispatch('getRegionData', {
389-
locale: targetLocale
390-
})
388+
await dispatch('getRegionData', targetLocale)
391389
}
392390
},
393391

394392
defaultInvidiousInstance: {
395393
defaultValue: '',
396-
sideEffectsHandler: ({ commit, getters }, value) => {
397-
if (value !== '' && getters.getCurrentInvidiousInstance !== value) {
394+
sideEffectsHandler: ({ commit, rootState }, value) => {
395+
if (value !== '' && rootState.invidious.currentInvidiousInstance !== value) {
398396
commit('setCurrentInvidiousInstance', value)
399397
}
400398
}
@@ -420,6 +418,8 @@ const stateWithSideEffects = {
420418
}
421419
}
422420

421+
const settingsWithSideEffects = Object.keys(stateWithSideEffects)
422+
423423
const customState = {
424424
}
425425

@@ -428,28 +428,8 @@ const customGetters = {
428428

429429
const customMutations = {}
430430

431-
/**********/
432-
/*
433-
* DO NOT TOUCH THIS SECTION
434-
* If you wanna add to custom data or logic to the module,
435-
* do so in the aproppriate `custom_` variable
436-
*
437-
* Some of the custom actions below use these properties, so I'll be
438-
* adding them here instead of further down for clarity's sake
439-
*/
440-
Object.assign(customState, {
441-
settingsWithSideEffects: Object.keys(stateWithSideEffects)
442-
})
443-
444-
Object.assign(customGetters, {
445-
settingHasSideEffects: (state) => {
446-
return (id) => state.settingsWithSideEffects.includes(id)
447-
}
448-
})
449-
/**********/
450-
451431
const customActions = {
452-
grabUserSettings: async ({ commit, dispatch, getters }) => {
432+
grabUserSettings: async ({ commit, dispatch }) => {
453433
try {
454434
// Assigning default settings for settings that have side effects
455435
const userSettings = Object.entries(Object.assign({},
@@ -459,7 +439,7 @@ const customActions = {
459439

460440
for (const setting of userSettings) {
461441
const [_id, value] = setting
462-
if (getters.settingHasSideEffects(_id)) {
442+
if (settingsWithSideEffects.includes(_id)) {
463443
dispatch(defaultSideEffectsTriggerId(_id), value)
464444
}
465445

@@ -473,14 +453,14 @@ const customActions = {
473453
},
474454

475455
// Should be a root action, but we'll tolerate
476-
setupListenersToSyncWindows: ({ commit, dispatch, getters }) => {
456+
setupListenersToSyncWindows: ({ commit, dispatch }) => {
477457
if (process.env.IS_ELECTRON) {
478458
const { ipcRenderer } = require('electron')
479459

480460
ipcRenderer.on(IpcChannels.SYNC_SETTINGS, (_, { event, data }) => {
481461
switch (event) {
482462
case SyncEvents.GENERAL.UPSERT:
483-
if (getters.settingHasSideEffects(data._id)) {
463+
if (settingsWithSideEffects.includes(data._id)) {
484464
dispatch(defaultSideEffectsTriggerId(data._id), data.value)
485465
}
486466

@@ -615,15 +595,15 @@ for (const settingId of Object.keys(state)) {
615595
mutations[mutationId] = (state, value) => { state[settingId] = value }
616596

617597
// If setting has side effects, generate action to handle them
618-
if (Object.keys(stateWithSideEffects).includes(settingId)) {
598+
if (settingsWithSideEffects.includes(settingId)) {
619599
actions[triggerId] = stateWithSideEffects[settingId].sideEffectsHandler
620600
}
621601

622-
actions[updaterId] = async ({ commit, dispatch, getters }, value) => {
602+
actions[updaterId] = async ({ commit, dispatch }, value) => {
623603
try {
624604
await DBSettingHandlers.upsert(settingId, value)
625605

626-
if (getters.settingHasSideEffects(settingId)) {
606+
if (settingsWithSideEffects.includes(settingId)) {
627607
dispatch(triggerId, value)
628608
}
629609

src/renderer/store/modules/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ const actions = {
401401
commit('setShowProgressBar', value)
402402
},
403403

404-
async getRegionData ({ commit }, { locale }) {
404+
async getRegionData ({ commit }, locale) {
405405
const localePathExists = process.env.GEOLOCATION_NAMES.includes(locale)
406406

407407
const url = createWebURL(`/static/geolocations/${localePathExists ? locale : 'en-US'}.json`)

0 commit comments

Comments
 (0)