forked from platypush/platypush
Better entities caching on the frontend.
This commit is contained in:
parent
79871e0fa1
commit
6cd9cb6e76
1 changed files with 10 additions and 10 deletions
|
@ -252,8 +252,7 @@ export default {
|
|||
await this.request('entities.scan', args)
|
||||
},
|
||||
|
||||
async sync(setLoading=true) {
|
||||
if (setLoading)
|
||||
async sync() {
|
||||
this.loading = true
|
||||
|
||||
try {
|
||||
|
@ -273,7 +272,6 @@ export default {
|
|||
this.selector.selectedEntities = this.entityGroups.id
|
||||
this.refreshEntitiesCache()
|
||||
} finally {
|
||||
if (setLoading)
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
|
@ -367,11 +365,15 @@ export default {
|
|||
},
|
||||
|
||||
loadCachedEntities() {
|
||||
const cachedEntities = localStorage.getItem('entities')
|
||||
const cachedEntities = window.localStorage.getItem('entities')
|
||||
if (cachedEntities) {
|
||||
this.entities = JSON.parse(cachedEntities)
|
||||
if (this.entities) {
|
||||
Object.values(this.entities).forEach((entity) => this.onEntityUpdate({entity: entity}))
|
||||
this.selector.selectedEntities = this.entityGroups.id
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
|
@ -401,11 +403,9 @@ export default {
|
|||
await this.sync()
|
||||
await this.refresh()
|
||||
} else {
|
||||
this.refresh()
|
||||
this.sync(false).then(() => this.refresh())
|
||||
await this.request('entities.scan')
|
||||
}
|
||||
|
||||
// Refresh the entities cache every 10 seconds
|
||||
setInterval(() => this.refreshEntitiesCache(), 10000)
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue