|
@@ -5,7 +5,9 @@ import {
|
|
DATA_LEVELS,
|
|
DATA_LEVELS,
|
|
ID_VARIANTS,
|
|
ID_VARIANTS,
|
|
VARIANT_IDS,
|
|
VARIANT_IDS,
|
|
- RELATIONS // FIXME REMOVE WHEN DB MAJ
|
|
|
|
|
|
+ RELATIONS,
|
|
|
|
+ reduceQueryIds,
|
|
|
|
+ reduceQueryLevels
|
|
} from '@/store/utils'
|
|
} from '@/store/utils'
|
|
import {
|
|
import {
|
|
AllNodesOfVariant
|
|
AllNodesOfVariant
|
|
@@ -116,35 +118,22 @@ export default {
|
|
},
|
|
},
|
|
|
|
|
|
actions: {
|
|
actions: {
|
|
- async 'GET_ALL_NODES_IDS' ({ state, commit }, variant) {
|
|
|
|
|
|
+ async 'GET_ALL_NODES_IDS' ({ state, commit }, { variant, dataLevel = 'initial' }) {
|
|
if (state.ids[variant] === undefined) {
|
|
if (state.ids[variant] === undefined) {
|
|
- // FIXME UPDATE WHEN QUERY OK
|
|
|
|
- // await api.query(AllNodesOfVariant, { variantId: VARIANT_IDS[variant] }).then(data => {
|
|
|
|
- await api.query(AllNodesOfVariant, { variantId: VARIANT_IDS[variant] }).then(data => {
|
|
|
|
- commit('SET_ALL_NODES_IDS', [variant, data.nodes])
|
|
|
|
|
|
+ const levels = reduceQueryLevels(DATA_LEVELS[dataLevel])
|
|
|
|
+ await api.queryAllNodes(VARIANT_IDS[variant], levels).then(({ nodes }) => {
|
|
|
|
+ commit('SET_ALL_NODES_IDS', [variant, nodes])
|
|
|
|
+ commit('ADD_NODES', [nodes, DATA_LEVELS[dataLevel]])
|
|
})
|
|
})
|
|
}
|
|
}
|
|
return state.ids[variant]
|
|
return state.ids[variant]
|
|
},
|
|
},
|
|
|
|
|
|
async 'GET_NODES' ({ state, commit, getters }, { ids, dataLevel = 'partial' }) {
|
|
async 'GET_NODES' ({ state, commit, getters }, { ids, dataLevel = 'partial' }) {
|
|
- const lvl = DATA_LEVELS[dataLevel]
|
|
|
|
- const nodesIdsToQuery = []
|
|
|
|
- let lowestLvl = lvl
|
|
|
|
- for (const id of ids) {
|
|
|
|
- const nodeLvl = id in state.nodes ? state.nodes[id].dataLevel : -1
|
|
|
|
- if (nodeLvl < lvl) {
|
|
|
|
- nodesIdsToQuery.push(id)
|
|
|
|
- }
|
|
|
|
- if (nodeLvl < lowestLvl) {
|
|
|
|
- lowestLvl = nodeLvl
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (nodesIdsToQuery.length) {
|
|
|
|
- const levelsToQuery = Array(lvl - lowestLvl).fill(lowestLvl + 1).map((v, i) => v + i)
|
|
|
|
- await api.queryNodes(nodesIdsToQuery, levelsToQuery).then(data => {
|
|
|
|
- commit('ADD_NODES', [data.nodes, lvl])
|
|
|
|
|
|
+ const { idsToQuery, levelsToQuery } = reduceQueryIds(ids, dataLevel, state.nodes)
|
|
|
|
+ if (idsToQuery) {
|
|
|
|
+ await api.queryNodes(idsToQuery, levelsToQuery).then(data => {
|
|
|
|
+ commit('ADD_NODES', [data.nodes, DATA_LEVELS[dataLevel]])
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|