Skip to content

Commit 5b06ccf

Browse files
MXS-3681 Remove active_tree_node from localStorage
`active_tree_node` is used to automatically query preview data when user refreshes the browser. Though this brings convenience but querying preview data with large number of rows causes slow response effect on user interface. In addition, user can always set max rows to any number, so on inital rendering, pre-query should be avoided. This keeps `active_tree_node` in memory. i.e. to store it in `db_tree_map` and release when browser refreshes.
1 parent 7db73f8 commit 5b06ccf

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

maxgui/src/pages/QueryPage/DbListTree.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ export default {
131131
},
132132
computed: {
133133
...mapState({
134-
active_tree_node: state => state.query.active_tree_node,
135134
expanded_nodes: state => state.query.expanded_nodes,
135+
active_wke_id: state => state.query.active_wke_id,
136136
}),
137137
...mapGetters({
138138
getDbTreeData: 'query/getDbTreeData',
139+
getActiveTreeNode: 'query/getActiveTreeNode',
139140
}),
140141
filter() {
141142
return (item, search, textKey) => item[textKey].indexOf(search) > -1
@@ -145,11 +146,18 @@ export default {
145146
},
146147
activeNodes: {
147148
get() {
148-
return [this.active_tree_node]
149+
return [this.getActiveTreeNode]
149150
},
150151
set(v) {
151152
const activeNodes = this.minimizeNodes(v)
152-
if (activeNodes.length) this.SET_ACTIVE_TREE_NODE(activeNodes[0])
153+
if (activeNodes.length) {
154+
this.UPDATE_DB_TREE_MAP({
155+
id: this.active_wke_id,
156+
payload: {
157+
active_tree_node: activeNodes[0],
158+
},
159+
})
160+
}
153161
},
154162
},
155163
},
@@ -167,7 +175,7 @@ export default {
167175
},
168176
methods: {
169177
...mapMutations({
170-
SET_ACTIVE_TREE_NODE: 'query/SET_ACTIVE_TREE_NODE',
178+
UPDATE_DB_TREE_MAP: 'query/UPDATE_DB_TREE_MAP',
171179
SET_EXPANDED_NODES: 'query/SET_EXPANDED_NODES',
172180
}),
173181
addExpandedNodesWatcher() {

maxgui/src/pages/QueryPage/PreviewDataTab.vue

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<truncate-string
88
:maxWidth="260"
99
:nudgeLeft="16"
10-
:text="$typy(active_tree_node, 'id').safeObject"
10+
:text="$typy(getActiveTreeNode, 'id').safeObject"
1111
/>
1212
</div>
1313
<v-tabs
@@ -130,21 +130,20 @@ export default {
130130
},
131131
computed: {
132132
...mapState({
133-
active_tree_node: state => state.query.active_tree_node,
134133
SQL_QUERY_MODES: state => state.app_config.SQL_QUERY_MODES,
135134
curr_query_mode: state => state.query.curr_query_mode,
136135
curr_cnct_resource: state => state.query.curr_cnct_resource,
137-
active_wke_id: state => state.query.active_wke_id,
138136
}),
139137
...mapGetters({
140138
getPrvwDataRes: 'query/getPrvwDataRes',
141139
getPrvwSentTime: 'query/getPrvwSentTime',
142140
getPrvwExeTime: 'query/getPrvwExeTime',
143141
getPrvwTotalDuration: 'query/getPrvwTotalDuration',
144142
getLoadingPrvw: 'query/getLoadingPrvw',
143+
getActiveTreeNode: 'query/getActiveTreeNode',
145144
}),
146145
validConn() {
147-
return Boolean(this.active_tree_node.id && this.curr_cnct_resource.id)
146+
return Boolean(this.getActiveTreeNode.id && this.curr_cnct_resource.id)
148147
},
149148
isPrwDataLoading() {
150149
return (
@@ -168,9 +167,8 @@ export default {
168167
if (!this.isPrwDataLoading && this.validConn) await this.handleFetch(activeView)
169168
},
170169
},
171-
async activated() {
170+
activated() {
172171
this.setHeaderHeight()
173-
await this.autoFetchActiveNode()
174172
},
175173
methods: {
176174
...mapMutations({
@@ -183,21 +181,7 @@ export default {
183181
if (!this.$refs.header) return
184182
this.headerHeight = this.$refs.header.clientHeight
185183
},
186-
async autoFetchActiveNode() {
187-
if (this.curr_cnct_resource.id)
188-
switch (this.activeView) {
189-
// Auto fetch preview data if there is active_tree_node in localStorage
190-
case this.SQL_QUERY_MODES.PRVW_DATA_DETAILS:
191-
case this.SQL_QUERY_MODES.PRVW_DATA: {
192-
const hasActiveNode = this.$typy(this.active_tree_node, 'id').safeObject
193-
const isFetchingAlready = this.getLoadingPrvw(this.activeView)
194-
const isDataEmpty = this.$typy(this.getPrvwDataRes(this.activeView))
195-
.isEmptyObject
196-
if (hasActiveNode && !isFetchingAlready && isDataEmpty)
197-
await this.fetchActiveNodeData(this.activeView)
198-
}
199-
}
200-
},
184+
201185
/**
202186
* This function checks if there is no preview data or details data
203187
* before dispatching action to fetch either preview data or details
@@ -219,7 +203,7 @@ export default {
219203
*/
220204
async fetchActiveNodeData(SQL_QUERY_MODE) {
221205
await this.fetchPrvw({
222-
tblId: this.$typy(this.active_tree_node, 'id').safeObject,
206+
tblId: this.$typy(this.getActiveTreeNode, 'id').safeObject,
223207
prvwMode: SQL_QUERY_MODE,
224208
})
225209
},

maxgui/src/store/query.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function sidebarStates() {
3030
is_sidebar_collapsed: false,
3131
search_schema: '',
3232
active_db: '',
33-
active_tree_node: {},
3433
expanded_nodes: [],
3534
}
3635
}
@@ -120,7 +119,7 @@ export default {
120119
is_fullscreen: false,
121120
rc_target_names_map: {},
122121
// sidebar states
123-
db_tree_map: [],
122+
db_tree_map: {},
124123
// results states
125124
prvw_data_map: {},
126125
prvw_data_details_map: {},
@@ -165,9 +164,6 @@ export default {
165164
...{ [id]: { ...state.db_tree_map[id], ...payload } },
166165
}
167166
},
168-
SET_ACTIVE_TREE_NODE(state, payload) {
169-
patch_wke_property(state, { obj: { active_tree_node: payload }, scope: this })
170-
},
171167
SET_EXPANDED_NODES(state, payload) {
172168
patch_wke_property(state, { obj: { expanded_nodes: payload }, scope: this })
173169
},
@@ -947,6 +943,9 @@ export default {
947943
},
948944
// sidebar getters
949945
getCurrDbTree: state => state.db_tree_map[state.active_wke_id] || {},
946+
getActiveTreeNode: (state, getters) => {
947+
return getters.getCurrDbTree.active_tree_node || {}
948+
},
950949
getDbTreeData: (state, getters) => {
951950
return getters.getCurrDbTree.data || []
952951
},

0 commit comments

Comments
 (0)