From 6cd9cb6e760b5a40d194043b7d47a00676ebe5d6 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 12 May 2023 03:18:22 +0200 Subject: [PATCH] Better entities caching on the frontend. --- .../src/components/panels/Entities/Index.vue | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue b/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue index 738072888..7905b266d 100644 --- a/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue +++ b/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue @@ -252,9 +252,8 @@ export default { await this.request('entities.scan', args) }, - async sync(setLoading=true) { - if (setLoading) - this.loading = true + async sync() { + this.loading = true try { this.entities = (await this.request('entities.get')).reduce((obj, entity) => { @@ -273,8 +272,7 @@ export default { this.selector.selectedEntities = this.entityGroups.id this.refreshEntitiesCache() } finally { - if (setLoading) - this.loading = false + this.loading = false } }, @@ -367,10 +365,14 @@ export default { }, loadCachedEntities() { - const cachedEntities = localStorage.getItem('entities') + const cachedEntities = window.localStorage.getItem('entities') if (cachedEntities) { this.entities = JSON.parse(cachedEntities) - return true + 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) },