Skip to content

Commit

Permalink
Use cacheable lists when possible (#1661)
Browse files Browse the repository at this point in the history
Closes #1650.
Depends on openhab/openhab-core#3335.

Will fetch items, things and rules with the `staticDataOnly` parameter set when appropriate.

Also-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Yannick Schaus <github@schaus.net>
  • Loading branch information
ghys committed Jul 2, 2023
1 parent 1f659cc commit 1257a0d
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 20 deletions.
Expand Up @@ -49,8 +49,7 @@ export default {
created () {
this.smartSelectParams.closeOnSelect = !(this.multiple)
if (!this.items || !this.items.length) {
// TODO use a Vuex store
this.$oh.api.get('/rest/items').then((items) => {
this.$oh.api.get('/rest/items?staticDataOnly=true').then((items) => {
this.sortAndFilterItems(items)
})
} else {
Expand Down
Expand Up @@ -46,8 +46,7 @@ export default {
},
created () {
this.smartSelectParams.closeOnSelect = !(this.multiple)
// TODO use a Vuex store
this.$oh.api.get('/rest/rules?summary=true').then((data) => {
this.$oh.api.get('/rest/rules?staticDataOnly=true').then((data) => {
this.scenes = data.filter((r) => r.tags.indexOf('Scene') >= 0).sort((a, b) => {
const labelA = a.name
const labelB = b.name
Expand Down
Expand Up @@ -235,7 +235,7 @@ export default {
}
server.on('completion', this.ternComplete)
})
this.$oh.api.get('/rest/items').then((data) => { this.$set(this, 'itemsCache', data) })
this.$oh.api.get('/rest/items?staticDataOnly=true').then((data) => { this.$set(this, 'itemsCache', data) })
}
const server = new _CodeMirror.TernServer({
defs: (this.mode.indexOf('version=ECMAScript-5.1') > 0) ? [EcmascriptDefs, NashornDefs] : [EcmascriptDefs, OpenhabJsDefs],
Expand Down
Expand Up @@ -33,8 +33,7 @@ export default {
},
created () {
this.smartSelectParams.closeOnSelect = !(this.multiple)
// TODO use a Vuex store
this.$oh.api.get('/rest/things?summary=true').then((data) => {
this.$oh.api.get('/rest/things?staticDataOnly=true').then((data) => {
this.things = data.sort((a, b) => {
const labelA = a.label || a.UID
const labelB = b.label || b.UID
Expand Down
Expand Up @@ -33,8 +33,7 @@ export default {
},
created () {
this.smartSelectParams.closeOnSelect = !(this.multiple)
// TODO use a Vuex store
this.$oh.api.get('/rest/things').then((data) => {
this.$oh.api.get('/rest/things?staticDataOnly=true').then((data) => {
this.things = data.sort((a, b) => {
const labelA = a.label
const labelB = b.label
Expand Down
Expand Up @@ -52,7 +52,7 @@ function getWidgetDefinitions (cm) {

function hintItems (cm, line, replaceAfterColon, addStatePropertySuffix, addQuotes) {
const cursor = cm.getCursor()
const promise = (itemsCache) ? Promise.resolve(itemsCache) : cm.state.$oh.api.get('/rest/items')
const promise = (itemsCache) ? Promise.resolve(itemsCache) : cm.state.$oh.api.get('/rest/items?staticDataOnly=true')
return promise.then((data) => {
if (!itemsCache) itemsCache = data
let ret = {
Expand Down
Expand Up @@ -14,7 +14,7 @@ function getModuleTypes (cm, section) {
function hintItems (cm, line, replaceAfterColon, replaceAfterLastSpace, addColonSuffix) {
const cursor = cm.getCursor()
if (!cm.state.$oh) return
const promise = (itemsCache) ? Promise.resolve(itemsCache) : cm.state.$oh.api.get('/rest/items')
const promise = (itemsCache) ? Promise.resolve(itemsCache) : cm.state.$oh.api.get('/rest/items?staticDataOnly=true')
return promise.then((data) => {
if (!itemsCache) itemsCache = data
let ret = {
Expand Down
Expand Up @@ -556,8 +556,8 @@ export default {
Promise.resolve(this.cachedObjects[2]),
Promise.resolve(this.cachedObjects[3])
] : [
this.$oh.api.get('/rest/items?metadata=.*'),
this.$oh.api.get('/rest/things?summary=true'),
this.$oh.api.get('/rest/items?staticDataOnly=true&metadata=.*'),
this.$oh.api.get('/rest/things?staticDataOnly=true'),
this.$oh.api.get('/rest/rules?summary=false'),
Promise.resolve(this.$store.getters.pages)
]
Expand Down
Expand Up @@ -149,7 +149,7 @@ export default {
load (update) {
// if (this.ready) return
this.loading = true
const items = this.$oh.api.get('/rest/items?metadata=.+')
const items = this.$oh.api.get('/rest/items?staticDataOnly=true&metadata=.+')
const links = this.$oh.api.get('/rest/links')
Promise.all([items, links]).then((data) => {
this.items = data[0]
Expand Down
Expand Up @@ -114,7 +114,7 @@ export default {
item.children.forEach(child => this.sortModel(child))
},
loadModel (page) {
this.$oh.api.get('/rest/items?metadata=semantics,listWidget,widgetOrder')
this.$oh.api.get('/rest/items?staticDataOnly=true&metadata=semantics,listWidget,widgetOrder')
.then((data) => {
this.items = data
let filteredItems = {
Expand Down
Expand Up @@ -131,7 +131,7 @@ export default {
created: false
}
this.$set(this, 'item', newItem)
this.$oh.api.get('/rest/items').then((items) => {
this.$oh.api.get('/rest/items?staticDataOnly=true').then((items) => {
this.items = items
this.ready = true
})
Expand Down
Expand Up @@ -292,7 +292,7 @@ export default {
load (update) {
// if (this.ready) return
this.loading = true
const items = this.$oh.api.get('/rest/items?metadata=.+')
const items = this.$oh.api.get('/rest/items?staticDataOnly=true&metadata=.+')
const links = this.$oh.api.get('/rest/links')
Promise.all([items, links]).then((data) => {
this.items = data[0]
Expand Down
Expand Up @@ -198,9 +198,9 @@ export default {
loadCounters () {
if (!this.apiEndpoints) return
if (this.$store.getters.apiEndpoint('inbox')) this.$oh.api.get('/rest/inbox').then((data) => { this.inboxCount = data.filter((e) => e.flag === 'NEW').length.toString() })
if (this.$store.getters.apiEndpoint('things')) this.$oh.api.get('/rest/things?summary=true').then((data) => { this.thingsCount = data.length.toString() })
if (this.$store.getters.apiEndpoint('items')) this.$oh.api.get('/rest/items').then((data) => { this.itemsCount = data.length.toString() })
if (this.$store.getters.apiEndpoint('ui')) this.$oh.api.get('/rest/ui/components/system:sitemap?summary=true').then((data) => { this.sitemapsCount = data.length })
if (this.$store.getters.apiEndpoint('things')) this.$oh.api.get('/rest/things?staticDataOnly=true').then((data) => { this.thingsCount = data.length.toString() })
if (this.$store.getters.apiEndpoint('items')) this.$oh.api.get('/rest/items?staticDataOnly=true').then((data) => { this.itemsCount = data.length.toString() })
if (this.$store.getters.apiEndpoint('ui')) this.$oh.api.get('/rest/ui/components/system:sitemap').then((data) => { this.sitemapsCount = data.length })
if (this.$store.getters.apiEndpoint('transformations')) this.$oh.api.get('/rest/transformations').then((data) => { this.transformationsCount = data.length })
},
navigateToStore (tab) {
Expand Down

0 comments on commit 1257a0d

Please sign in to comment.