Browse Source

refactor: if fieldsSet is defined use it for select query

Signed-off-by: Pranav C <pranavxc@gmail.com>
test/query-opt-imp
Pranav C 2 years ago
parent
commit
0f790e9e07
  1. 30
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

30
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -216,7 +216,7 @@ class BaseModelSqlv2 {
fieldsSet: args.fieldsSet, fieldsSet: args.fieldsSet,
viewId: this.viewId, viewId: this.viewId,
alias: INNER_QUERY_ALIAS, alias: INNER_QUERY_ALIAS,
validateFormula validateFormula,
}); });
if (+rest?.shuffle) { if (+rest?.shuffle) {
await this.shuffle({ qb: innerQb }); await this.shuffle({ qb: innerQb });
@ -1502,7 +1502,7 @@ class BaseModelSqlv2 {
viewId, viewId,
fieldsSet, fieldsSet,
alias, alias,
validateFormula validateFormula,
}: { }: {
fieldsSet?: Set<string>; fieldsSet?: Set<string>;
qb: Knex.QueryBuilder; qb: Knex.QueryBuilder;
@ -1511,16 +1511,26 @@ class BaseModelSqlv2 {
extractPkAndPv?: boolean; extractPkAndPv?: boolean;
viewId?: string; viewId?: string;
alias?: string; alias?: string;
validateFormula?:boolean validateFormula?: boolean;
}): Promise<void> { }): Promise<void> {
const view = await View.get(viewId); let viewOrTableColumns: Column[] | { fk_column_id?: string }[];
const viewColumns = viewId && (await View.getColumns(viewId));
const fields = Array.isArray(_fields) ? _fields : _fields?.split(',');
const res = {}; const res = {};
// const columns = _columns ?? (await this.model.getColumns()); let view: View;
// for (const column of columns) { let fields: string[] = [];
const viewOrTableColumns =
_columns || viewColumns || (await this.model.getColumns()); if (fieldsSet?.size) {
viewOrTableColumns = await this.model.getColumns();
} else {
view = await View.get(viewId);
const viewColumns = viewId && (await View.getColumns(viewId));
fields = Array.isArray(_fields) ? _fields : _fields?.split(',');
// const columns = _columns ?? (await this.model.getColumns());
// for (const column of columns) {
viewOrTableColumns =
_columns || viewColumns || (await this.model.getColumns());
}
for (const viewOrTableColumn of viewOrTableColumns) { for (const viewOrTableColumn of viewOrTableColumns) {
const column = const column =
viewOrTableColumn instanceof Column viewOrTableColumn instanceof Column

Loading…
Cancel
Save