Skip to content

Commit

Permalink
moving dbcache fxn to store; making refresh always true for now (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
havok2063 authored Aug 14, 2024
1 parent abc9e8e commit f1b5062
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
24 changes: 24 additions & 0 deletions src/store/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Utilities
import { defineStore } from 'pinia'
import axiosInstance from '@/axios'

export const useAppStore = defineStore('app', {
state: () => ({
Expand Down Expand Up @@ -84,6 +85,29 @@ export const useAppStore = defineStore('app', {
let default_val = (this.flat_db[column] === undefined && field === 'display_name') ? column : null

return this.flat_db[column] ? this.flat_db[column][field] : default_val;
},

async get_db_info(refresh: boolean = true) {
// get the database metadata info for column descriptions and such
// always refresh

if (!refresh && Object.keys(this.db_info).length !== 0) {
console.log('db info already loaded')
return
}

await axiosInstance.get('/info/database')
.then((response) => {
// store the db metadata
this.db_info = response.data

// flatten the db_info object
this.flat_db = Object.fromEntries(Object.entries(this.db_info).flatMap(([schema, table])=>Object.entries(table)))

})
.catch((error) => {
console.error(error.toJSON())
})
}

},
Expand Down
3 changes: 3 additions & 0 deletions src/views/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ async function set_fail(msg : string) {
onMounted(() => {
// get database info
store.get_db_info()
// set up API call endpoints
let endpoints = [
`/query/list/cartons`,
Expand Down
36 changes: 18 additions & 18 deletions src/views/Target.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,27 @@ function check_files(data) {
return empty ? false : true
}
async function get_db_info() {
// async function get_db_info() {
if (Object.keys(store.db_info).length !== 0) {
console.log('db info already loaded')
return
}
// if (Object.keys(store.db_info).length !== 0) {
// console.log('db info already loaded')
// return
// }
await axiosInstance.get('/info/database')
.then((response) => {
console.log('db info', response.data)
// store the db metadata
store.db_info = response.data
// await axiosInstance.get('/info/database')
// .then((response) => {
// console.log('db info', response.data)
// // store the db metadata
// store.db_info = response.data
// flatten the db_info object
store.flat_db = Object.fromEntries(Object.entries(store.db_info).flatMap(([schema, table])=>Object.entries(table)))
// // flatten the db_info object
// store.flat_db = Object.fromEntries(Object.entries(store.db_info).flatMap(([schema, table])=>Object.entries(table)))
})
.catch((error) => {
console.error(error.toJSON())
})
}
// })
// .catch((error) => {
// console.error(error.toJSON())
// })
// }
function convert_object( metadata) {
// temp function for converting to table
Expand Down Expand Up @@ -300,7 +300,7 @@ function isHighlighted(item) {
onMounted(() => {
// get database info
get_db_info()
store.get_db_info()
// get the available target info
get_target_info()
Expand Down

0 comments on commit f1b5062

Please sign in to comment.