Skip to content

Commit

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

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

Closes openhab#1650.

Signed-off-by: Yannick Schaus <github@schaus.net>
  • Loading branch information
ghys committed Jan 24, 2023
1 parent 86b6333 commit bc18fe4
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 18 deletions.
2 changes: 0 additions & 2 deletions bundles/org.openhab.ui.iconset.classic/.classpath
Expand Up @@ -21,13 +21,11 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="annotationpath" value="target/dependency"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="annotationpath" value="target/dependency"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
Expand Down
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?cacheable=true').then((items) => {
this.sortAndFilterItems(items)
})
} else {
Expand Down
Expand Up @@ -32,8 +32,7 @@ export default {
},
created () {
this.smartSelectParams.closeOnSelect = !(this.multiple)
// TODO use a Vuex store
this.$oh.api.get('/rest/rules').then((data) => {
this.$oh.api.get('/rest/rules&cacheable=true').then((data) => {
this.rules = data.sort((a, b) => {
const labelA = a.name
const labelB = b.name
Expand Down
Expand Up @@ -228,7 +228,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?cacheable=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').then((data) => {
this.$oh.api.get('/rest/things?cacheable=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?cacheable=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, addStatePropertySuffix) {
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?cacheable=true')
return promise.then((data) => {
if (!itemsCache) itemsCache = data
let ret = {
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?cacheable=true&metadata=.+')
const links = this.$oh.api.get('/rest/links')
Promise.all([items, links]).then((data) => {
this.items = data[0]
Expand Down
Expand Up @@ -120,7 +120,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?cacheable=true&metadata=semantics,listWidget,widgetOrder')
.then((data) => {
this.items = data
let filteredItems = {
Expand Down
Expand Up @@ -107,7 +107,7 @@ export default {
created: false
}
this.$set(this, 'item', newItem)
this.$oh.api.get('/rest/items').then((items) => {
this.$oh.api.get('/rest/items&cacheable=true').then((items) => {
this.items = items
this.ready = true
})
Expand Down
Expand Up @@ -288,7 +288,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?cacheable=true&metadata=.+')
const links = this.$oh.api.get('/rest/links')
Promise.all([items, links]).then((data) => {
this.items = data[0]
Expand Down
Expand Up @@ -187,9 +187,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?cacheable=true').then((data) => { this.thingsCount = data.length.toString() })
if (this.$store.getters.apiEndpoint('items')) this.$oh.api.get('/rest/items?cacheable=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 })
},
navigateToStore (tab) {
this.$f7.views.main.router.navigate('addons', { props: { initialTab: tab } })
Expand Down

0 comments on commit bc18fe4

Please sign in to comment.