Skip to content

Commit fe530e7

Browse files
committed
Cache all target item names at plugin install time
1 parent 265380e commit fe530e7

File tree

5 files changed

+103
-95
lines changed

5 files changed

+103
-95
lines changed

openc3-cosmos-init/plugins/packages/openc3-js-common/src/services/openc3Api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ export default class OpenC3Api {
287287
return this.exec('get_all_tlm_names', [target_name])
288288
}
289289

290-
get_all_tlm_items_metadata(target_name) {
291-
return this.exec('get_all_tlm_items_metadata', [target_name])
290+
get_all_tlm_item_names(target_name) {
291+
return this.exec('get_all_tlm_item_names', [target_name])
292292
}
293293

294294
async get_tlm_packet(target_name, packet_name, value_type, stale_time = 30) {

openc3-cosmos-init/plugins/packages/openc3-vue-common/src/components/TargetPacketItemChooser.vue

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
item-value="value"
5050
v-model="selectedPacketName"
5151
>
52-
<template v-if="showLatest" v-slot:prepend-item>
52+
<template v-if="includeLatestPacketInDropdown" v-slot:prepend-item>
5353
<v-list-item title="LATEST" @click="packetNameChanged('LATEST')" />
5454
<v-divider />
5555
</template>
@@ -330,6 +330,9 @@ export default {
330330
return this.selectedItemName
331331
}
332332
},
333+
includeLatestPacketInDropdown: function () {
334+
return this.showLatest && this.mode === 'tlm' // because LATEST cmd doesn't have much use and thus isn't currently implemented
335+
},
333336
},
334337
watch: {
335338
initialTargetName: function (val) {
@@ -413,56 +416,60 @@ export default {
413416
}
414417
this.internalDisabled = true
415418
416-
let getItemsPromise
417419
if (this.selectedPacketName === 'LATEST') {
418-
getItemsPromise = this.api.get_all_tlm_items_metadata(
419-
this.selectedTargetName,
420-
)
420+
this.api
421+
.get_all_tlm_item_names(this.selectedTargetName)
422+
.then((items) => {
423+
this.itemNames = items.map((item) => {
424+
return {
425+
label: item,
426+
value: item,
427+
description: `LATEST ${item}`,
428+
// Don't handle array for LATEST
429+
}
430+
})
431+
this.finishUpdateItems()
432+
})
421433
} else {
422434
const cmd = this.mode === 'tlm' ? 'get_tlm' : 'get_cmd'
423-
getItemsPromise = this.api[cmd](
424-
this.selectedTargetName,
425-
this.selectedPacketName,
426-
).then((packet) => packet.items)
427-
}
428-
getItemsPromise.then((items) => {
429-
this.itemNames = items
430-
.map((item) => {
431-
let label = item.name
432-
if (item.data_type == 'DERIVED') {
433-
label += ' *'
434-
}
435-
return [
436-
{
435+
this.api[cmd](this.selectedTargetName, this.selectedPacketName).then(
436+
(packet) => {
437+
this.itemNames = packet.items.map((item) => {
438+
let label = item.name
439+
if (item.data_type == 'DERIVED') {
440+
label += ' *'
441+
}
442+
return {
437443
label: label,
438444
value: item.name,
439445
description: item.description,
440446
array: item.array_size / item.bit_size,
441-
},
442-
]
443-
})
444-
.reduce((result, item) => {
445-
return result.concat(item)
446-
}, [])
447-
this.itemNames.sort((a, b) => (a.label > b.label ? 1 : -1))
448-
if (this.allowAll) {
449-
this.itemNames.unshift(this.ALL)
450-
}
451-
if (!this.selectedItemName) {
452-
this.selectedItemName = this.itemNames[0].value
453-
}
454-
this.description = this.itemNames[0].description
455-
this.itemIsArray()
456-
this.$emit('on-set', {
457-
targetName: this.selectedTargetName,
458-
packetName: this.selectedPacketName,
459-
itemName: this.selectedItemNameWIndex,
460-
valueType: this.selectedValueType,
461-
reduced: this.selectedReduced,
462-
reducedType: this.selectedReducedType,
463-
})
464-
this.internalDisabled = false
447+
}
448+
})
449+
this.itemNames.sort((a, b) => (a.label > b.label ? 1 : -1))
450+
this.finishUpdateItems()
451+
},
452+
)
453+
}
454+
},
455+
finishUpdateItems: function () {
456+
if (this.allowAll) {
457+
this.itemNames.unshift(this.ALL)
458+
}
459+
if (!this.selectedItemName) {
460+
this.selectedItemName = this.itemNames[0].value
461+
}
462+
this.description = this.itemNames[0].description
463+
this.itemIsArray()
464+
this.$emit('on-set', {
465+
targetName: this.selectedTargetName,
466+
packetName: this.selectedPacketName,
467+
itemName: this.selectedItemNameWIndex,
468+
valueType: this.selectedValueType,
469+
reduced: this.selectedReduced,
470+
reducedType: this.selectedReducedType,
465471
})
472+
this.internalDisabled = false
466473
},
467474
itemIsArray: function () {
468475
let i = this.itemNames.findIndex(

openc3-cosmos-init/plugins/packages/openc3-vue-common/src/tools/admin/tabs/MicroservicesTab.vue

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ export default {
164164
Api.get('/openc3-api/microservices/all').then((response) => {
165165
// Convert hash of microservices to array of microservices
166166
let microservices = []
167-
for (const [microservice_name, microservice] of Object.entries(response.data)) {
167+
for (const [microservice_name, microservice] of Object.entries(
168+
response.data,
169+
)) {
168170
microservices.push(microservice)
169171
}
170172
microservices.sort((a, b) => a.name.localeCompare(b.name))
@@ -173,44 +175,44 @@ export default {
173175
},
174176
startMicroservice: function (name) {
175177
this.$dialog
176-
.confirm(
177-
`Are you sure you want to restart microservice: ${name}?`,
178-
{
179-
okText: 'Start',
180-
cancelText: 'Cancel',
181-
},
182-
).then((dialog) => {
183-
Api.post(`/openc3-api/microservices/${name}/start`).then((response) => {
184-
this.alert = `Started ${name}`
185-
this.alertType = 'success'
186-
this.showAlert = true
187-
setTimeout(() => {
188-
this.showAlert = false
189-
}, 5000)
190-
}).then(() => {
191-
this.update()
192-
})
178+
.confirm(`Are you sure you want to restart microservice: ${name}?`, {
179+
okText: 'Start',
180+
cancelText: 'Cancel',
181+
})
182+
.then((dialog) => {
183+
Api.post(`/openc3-api/microservices/${name}/start`)
184+
.then((response) => {
185+
this.alert = `Started ${name}`
186+
this.alertType = 'success'
187+
this.showAlert = true
188+
setTimeout(() => {
189+
this.showAlert = false
190+
}, 5000)
191+
})
192+
.then(() => {
193+
this.update()
194+
})
193195
})
194196
},
195197
stopMicroservice: function (name) {
196198
this.$dialog
197-
.confirm(
198-
`Are you sure you want to stop microservice: ${name}?`,
199-
{
200-
okText: 'Stop',
201-
cancelText: 'Cancel',
202-
},
203-
).then((dialog) => {
204-
Api.post(`/openc3-api/microservices/${name}/stop`).then((response) => {
205-
this.alert = `Stopped ${name}`
206-
this.alertType = 'success'
207-
this.showAlert = true
208-
setTimeout(() => {
209-
this.showAlert = false
210-
}, 5000)
211-
}).then(() => {
212-
this.update()
213-
})
199+
.confirm(`Are you sure you want to stop microservice: ${name}?`, {
200+
okText: 'Stop',
201+
cancelText: 'Cancel',
202+
})
203+
.then((dialog) => {
204+
Api.post(`/openc3-api/microservices/${name}/stop`)
205+
.then((response) => {
206+
this.alert = `Stopped ${name}`
207+
this.alertType = 'success'
208+
this.showAlert = true
209+
setTimeout(() => {
210+
this.showAlert = false
211+
}, 5000)
212+
})
213+
.then(() => {
214+
this.update()
215+
})
214216
})
215217
},
216218
showMicroservice: function (name) {

openc3/lib/openc3/api/tlm_api.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module Api
4848
'get_all_telemetry', # DEPRECATED
4949
'get_all_tlm_names',
5050
'get_all_telemetry_names', # DEPRECATED
51-
'get_all_tlm_items_metadata',
51+
'get_all_tlm_item_names',
5252
'get_tlm',
5353
'get_telemetry', # DEPRECATED
5454
'get_item',
@@ -315,12 +315,13 @@ def get_all_tlm_names(target_name, hidden: false, manual: false, scope: $openc3_
315315
end
316316
alias get_all_telemetry_names get_all_tlm_names
317317

318-
# Returns an array of all the item hashes for every packet in a target
318+
# Returns an array of all the item names for every packet in a target
319319
#
320320
# @param target_name [String] Name of the taret
321321
# @return [Array<String>] Array of all telemetry item names
322-
def get_all_tlm_items_metadata(target_name, manual: false, scope: $openc3_scope, token: $openc3_token)
323-
TargetModel.all_items_metadata(target_name, scope: scope)
322+
def get_all_tlm_item_names(target_name, manual: false, scope: $openc3_scope, token: $openc3_token)
323+
authorize(permission: 'tlm', target_name: target_name, manual: manual, scope: scope, token: token)
324+
TargetModel.all_item_names(target_name, scope: scope)
324325
end
325326

326327
# Returns a telemetry packet hash

openc3/lib/openc3/models/target_model.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,9 @@ def self.packet_items(target_name, packet_name, items, type: :TLM, scope:)
257257
found
258258
end
259259

260-
# @return [Array<Hash>] All the item hashes for every packet in a target
261-
def self.all_items_metadata(target_name, type: :TLM, scope:)
262-
items = []
263-
packets = packets(target_name, type: type, scope: scope)
264-
items += packets.flat_map do |packet|
265-
packet['items'].map do |item|
266-
item.slice('name', 'description', 'data_type', 'array_size', 'bit_size')
267-
end
268-
end
269-
items.uniq! { |i| i['name'] } # since this would be used by `<target_name> LATEST <item_name>`
270-
items.sort_by! { |i| i['name'] }
260+
# @return [Array<String>] All the item names for every packet in a target
261+
def self.all_item_names(target_name, type: :TLM, scope:)
262+
items = Store.zrange("#{scope}__openc3tlm__#{target_name}__allitems", 0, -1)
271263
items
272264
end
273265

@@ -775,6 +767,11 @@ def update_target_model(system)
775767
update()
776768
end
777769

770+
def add_to_target_allitems_list(target_name, item)
771+
score = 0 # https://redis.io/docs/latest/develop/data-types/sorted-sets/#lexicographical-scores
772+
Store.zadd("#{@scope}__openc3tlm__#{target_name}__allitems", score, item.name)
773+
end
774+
778775
def update_store_telemetry(packet_hash, clear_old: true)
779776
packet_hash.each do |target_name, packets|
780777
Store.del("#{@scope}__openc3tlm__#{target_name}") if clear_old
@@ -789,6 +786,7 @@ def update_store_telemetry(packet_hash, clear_old: true)
789786
json_hash = Hash.new
790787
packet.sorted_items.each do |item|
791788
json_hash[item.name] = nil
789+
add_to_target_allitems_list(target_name, item)
792790
end
793791
CvtModel.set(json_hash, target_name: packet.target_name, packet_name: packet.packet_name, scope: @scope)
794792
end

0 commit comments

Comments
 (0)