optimise the on-load queries on console using bulk api (close #1191) (#1196)

This commit is contained in:
Aravind Shankar 2018-12-17 13:16:54 +05:30 committed by Shahidh K Muhammed
parent 460fcfa755
commit 1548b82e0e
3 changed files with 101 additions and 67 deletions

View File

@ -33,6 +33,94 @@ const MAKE_REQUEST = 'ModifyTable/MAKE_REQUEST';
const REQUEST_SUCCESS = 'ModifyTable/REQUEST_SUCCESS';
const REQUEST_ERROR = 'ModifyTable/REQUEST_ERROR';
const initQueries = {
schemaList: {
type: 'select',
args: {
table: {
name: 'schemata',
schema: 'information_schema',
},
columns: ['schema_name'],
order_by: [{ column: 'schema_name', type: 'asc', nulls: 'last' }],
where: {
schema_name: {
$nin: [
'information_schema',
'pg_catalog',
'hdb_catalog',
'hdb_views',
],
},
},
},
},
loadSchema: {
type: 'select',
args: {
table: {
name: 'hdb_table',
schema: 'hdb_catalog',
},
columns: [
'*.*',
{
name: 'columns',
columns: ['*.*'],
order_by: [{ column: 'column_name', type: 'asc', nulls: 'last' }],
},
],
where: { table_schema: '' },
order_by: [{ column: 'table_name', type: 'asc', nulls: 'last' }],
},
},
loadUntrackedSchema: {
type: 'select',
args: {
table: {
name: 'tables',
schema: 'information_schema',
},
columns: ['table_name'],
where: {
table_schema: '',
},
},
},
};
const fetchDataInit = () => (dispatch, getState) => {
const url = Endpoints.getSchema;
const body = {
type: 'bulk',
args: [
initQueries.schemaList,
initQueries.loadSchema,
initQueries.loadUntrackedSchema,
],
};
// set schema in queries
const currentSchema = getState().tables.currentSchema;
body.args[1].args.where.table_schema = currentSchema;
body.args[2].args.where.table_schema = currentSchema;
const options = {
credentials: globalCookiePolicy,
method: 'POST',
headers: dataHeaders(getState),
body: JSON.stringify(body),
};
return dispatch(requestAction(url, options)).then(
data => {
dispatch({ type: FETCH_SCHEMA_LIST, schemaList: data[0] });
dispatch({ type: LOAD_SCHEMA, allSchemas: data[1] });
dispatch({ type: LOAD_UNTRACKED_SCHEMA, untrackedSchemas: data[2] });
},
error => {
console.error('Failed to fetch schema ' + JSON.stringify(error));
}
);
};
/* ************ action creators *********************** */
const fetchSchemaList = () => (dispatch, getState) => {
const url = Endpoints.getSchema;
@ -40,27 +128,7 @@ const fetchSchemaList = () => (dispatch, getState) => {
credentials: globalCookiePolicy,
method: 'POST',
headers: dataHeaders(getState),
body: JSON.stringify({
type: 'select',
args: {
table: {
name: 'schemata',
schema: 'information_schema',
},
columns: ['schema_name'],
order_by: [{ column: 'schema_name', type: 'asc', nulls: 'last' }],
where: {
schema_name: {
$nin: [
'information_schema',
'pg_catalog',
'hdb_catalog',
'hdb_views',
],
},
},
},
}),
body: JSON.stringify(initQueries.schemaList),
};
return dispatch(requestAction(url, options)).then(
data => {
@ -75,29 +143,13 @@ const fetchSchemaList = () => (dispatch, getState) => {
const loadSchema = () => (dispatch, getState) => {
const url = Endpoints.getSchema;
const currentSchema = getState().tables.currentSchema;
const body = initQueries.loadSchema;
body.args.where.table_schema = currentSchema;
const options = {
credentials: globalCookiePolicy,
method: 'POST',
headers: dataHeaders(getState),
body: JSON.stringify({
type: 'select',
args: {
table: {
name: 'hdb_table',
schema: 'hdb_catalog',
},
columns: [
'*.*',
{
name: 'columns',
columns: ['*.*'],
order_by: [{ column: 'column_name', type: 'asc', nulls: 'last' }],
},
],
where: { table_schema: currentSchema },
order_by: [{ column: 'table_name', type: 'asc', nulls: 'last' }],
},
}),
body: JSON.stringify(body),
};
return dispatch(requestAction(url, options)).then(
data => {
@ -145,23 +197,13 @@ const fetchViewInfoFromInformationSchema = (schemaName, viewName) => (
const loadUntrackedSchema = () => (dispatch, getState) => {
const url = Endpoints.getSchema;
const currentSchema = getState().tables.currentSchema;
const body = initQueries.loadUntrackedSchema;
body.args.where.table_name = currentSchema;
const options = {
credentials: globalCookiePolicy,
method: 'POST',
headers: dataHeaders(getState),
body: JSON.stringify({
type: 'select',
args: {
table: {
name: 'tables',
schema: 'information_schema',
},
columns: ['table_name'],
where: {
table_schema: currentSchema,
},
},
}),
body: JSON.stringify(body),
};
return dispatch(requestAction(url, options)).then(
data => {
@ -513,6 +555,7 @@ export {
UPDATE_CURRENT_SCHEMA,
loadUntrackedRelations,
fetchSchemaList,
fetchDataInit,
ACCESS_KEY_ERROR,
UPDATE_DATA_HEADERS,
UPDATE_REMOTE_SCHEMA_MANUAL_REL,

View File

@ -25,9 +25,7 @@ import {
} from '.';
import {
loadSchema,
loadUntrackedSchema,
fetchSchemaList,
fetchDataInit,
UPDATE_CURRENT_SCHEMA,
// UPDATE_DATA_HEADERS,
// ACCESS_KEY_ERROR,
@ -146,9 +144,7 @@ const dataRouter = (connect, store, composeOnEnterHooks) => {
type: UPDATE_CURRENT_SCHEMA,
currentSchema: currentSchema,
}),
store.dispatch(fetchSchemaList()),
store.dispatch(loadSchema()),
store.dispatch(loadUntrackedSchema()),
store.dispatch(fetchDataInit()),
]).then(
() => {
cb();

View File

@ -15,10 +15,8 @@ import {
addAllUntrackedTablesSql,
} from '../Add/AddExistingTableViewActions';
import {
loadSchema,
loadUntrackedSchema,
loadUntrackedRelations,
fetchSchemaList,
fetchDataInit,
LOAD_UNTRACKED_RELATIONS,
UPDATE_CURRENT_SCHEMA,
} from '../DataActions';
@ -36,9 +34,7 @@ class Schema extends Component {
};
// Initialize this table
const dispatch = this.props.dispatch;
dispatch(fetchSchemaList());
dispatch(loadSchema());
dispatch(loadUntrackedSchema());
dispatch(fetchDataInit());
const untrackedRelations = getAllUnTrackedRelations(
this.props.schema,
this.props.currentSchema
@ -76,8 +72,7 @@ class Schema extends Component {
dispatch(push(`${appPrefix}/schema/${updatedSchema}`));
Promise.all([
dispatch({ type: UPDATE_CURRENT_SCHEMA, currentSchema: updatedSchema }),
dispatch(loadSchema()),
dispatch(loadUntrackedSchema()),
dispatch(fetchDataInit()),
dispatch(loadUntrackedRelations()),
]);
};