throttle push config + cleanup excessive calls
This commit is contained in:
parent
55fdb8687a
commit
c4c4f3bae7
2 changed files with 22 additions and 21 deletions
|
|
@ -350,7 +350,6 @@ export const useInterfaceStore = defineStore('interface', {
|
||||||
path: 'simple.styleCustomData',
|
path: 'simple.styleCustomData',
|
||||||
value: null,
|
value: null,
|
||||||
})
|
})
|
||||||
useSyncConfigStore().pushSyncConfig()
|
|
||||||
},
|
},
|
||||||
resetThemeV3Palette() {
|
resetThemeV3Palette() {
|
||||||
useSyncConfigStore().setPreference({
|
useSyncConfigStore().setPreference({
|
||||||
|
|
@ -361,7 +360,6 @@ export const useInterfaceStore = defineStore('interface', {
|
||||||
path: 'simple.paletteCustomData',
|
path: 'simple.paletteCustomData',
|
||||||
value: null,
|
value: null,
|
||||||
})
|
})
|
||||||
useSyncConfigStore().pushSyncConfig()
|
|
||||||
},
|
},
|
||||||
resetThemeV2() {
|
resetThemeV2() {
|
||||||
useSyncConfigStore().setPreference({ path: 'simple.theme', value: null })
|
useSyncConfigStore().setPreference({ path: 'simple.theme', value: null })
|
||||||
|
|
@ -373,7 +371,6 @@ export const useInterfaceStore = defineStore('interface', {
|
||||||
path: 'simple.customThemeSource',
|
path: 'simple.customThemeSource',
|
||||||
value: null,
|
value: null,
|
||||||
})
|
})
|
||||||
useSyncConfigStore().pushSyncConfig()
|
|
||||||
},
|
},
|
||||||
async getThemeData() {
|
async getThemeData() {
|
||||||
const getData = async (resource, index, customData, name) => {
|
const getData = async (resource, index, customData, name) => {
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,11 @@ import {
|
||||||
takeRight,
|
takeRight,
|
||||||
uniqWith,
|
uniqWith,
|
||||||
unset,
|
unset,
|
||||||
|
throttle,
|
||||||
} from 'lodash'
|
} from 'lodash'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { toRaw } from 'vue'
|
import { toRaw } from 'vue'
|
||||||
|
import sum from 'hash-sum'
|
||||||
|
|
||||||
import { CURRENT_UPDATE_COUNTER } from 'src/components/update_notification/update_notification.js'
|
import { CURRENT_UPDATE_COUNTER } from 'src/components/update_notification/update_notification.js'
|
||||||
|
|
||||||
|
|
@ -395,7 +397,7 @@ export const _resetFlags = (
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export const _resetPrefs = (
|
const _resetPrefs = (
|
||||||
totalPrefs,
|
totalPrefs,
|
||||||
totalFlags,
|
totalFlags,
|
||||||
knownKeys = defaultState.flagStorage,
|
knownKeys = defaultState.flagStorage,
|
||||||
|
|
@ -419,7 +421,7 @@ export const _resetPrefs = (
|
||||||
return totalPrefs
|
return totalPrefs
|
||||||
}
|
}
|
||||||
|
|
||||||
export const _doMigrations = async (data, setPreference) => {
|
const _doMigrations = async (data, setPreference) => {
|
||||||
if (data._version < VERSION) {
|
if (data._version < VERSION) {
|
||||||
console.debug(
|
console.debug(
|
||||||
'Data has older version, seeing if there any migrations that can be applied',
|
'Data has older version, seeing if there any migrations that can be applied',
|
||||||
|
|
@ -447,6 +449,18 @@ export const _doMigrations = async (data, setPreference) => {
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
const _pushSyncConfig = throttle((force, root) => {
|
||||||
|
const needPush = root.dirty || force
|
||||||
|
if (!needPush) return
|
||||||
|
root.updateCache({ username: window.vuex.state.users.currentUser.fqn })
|
||||||
|
const params = { pleroma_settings_store: { 'pleroma-fe': root.cache } }
|
||||||
|
window.vuex.state.api.backendInteractor
|
||||||
|
.updateProfileJSON({ params })
|
||||||
|
.then((user) => {
|
||||||
|
root.initSyncConfig(user)
|
||||||
|
root.dirty = false
|
||||||
|
})
|
||||||
|
}, 5000)
|
||||||
|
|
||||||
export const useSyncConfigStore = defineStore('sync_config', {
|
export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
state() {
|
state() {
|
||||||
|
|
@ -666,12 +680,11 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
// discarding timestamps and versions
|
// discarding timestamps and versions
|
||||||
const { _timestamp: _0, _version: _1, ...recentData } = recent
|
const { _timestamp: _0, _version: _1, ...recentData } = recent
|
||||||
const { _timestamp: _2, _version: _3, ...staleData } = stale
|
const { _timestamp: _2, _version: _3, ...staleData } = stale
|
||||||
dirty = !isEqual(
|
dirty = sum(recentData) !== sum(staleData)
|
||||||
// Something wrong happens if we compare both objects directly
|
console.log(sum(recentData), sum(staleData), recentData.prefsStorage)
|
||||||
// or with cloneDeep()
|
console.log(sum(recentData.prefsStorage), sum(staleData.prefsStorage))
|
||||||
JSON.parse(JSON.stringify(recentData)),
|
console.log('J', sum(recentData.prefsStorage._journal), sum(staleData.prefsStorage._journal))
|
||||||
JSON.parse(JSON.stringify(staleData)),
|
console.log('S', sum(recentData.prefsStorage.simple), sum(staleData.prefsStorage.simple))
|
||||||
)
|
|
||||||
console.debug(`Data ${dirty ? 'needs' : "doesn't need"} merging`)
|
console.debug(`Data ${dirty ? 'needs' : "doesn't need"} merging`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -707,16 +720,7 @@ export const useSyncConfigStore = defineStore('sync_config', {
|
||||||
this.pushSyncConfig()
|
this.pushSyncConfig()
|
||||||
},
|
},
|
||||||
pushSyncConfig({ force = false } = {}) {
|
pushSyncConfig({ force = false } = {}) {
|
||||||
const needPush = this.dirty || force
|
_pushSyncConfig(force, this)
|
||||||
if (!needPush) return
|
|
||||||
this.updateCache({ username: window.vuex.state.users.currentUser.fqn })
|
|
||||||
const params = { pleroma_settings_store: { 'pleroma-fe': this.cache } }
|
|
||||||
window.vuex.state.api.backendInteractor
|
|
||||||
.updateProfileJSON({ params })
|
|
||||||
.then((user) => {
|
|
||||||
this.initSyncConfig(user)
|
|
||||||
this.dirty = false
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue