Browse Source

refactor: revert subquery implementation since it won't improve the performance

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5379/head
Pranav C 2 years ago
parent
commit
a4a6e924c9
  1. 29
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

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

@ -57,10 +57,6 @@ const GROUP_COL = '__nc_group_id';
const nanoidv2 = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz', 14);
const { v4: uuidv4 } = require('uuid');
const INNER_QUERY_ALIAS = '__nc_inner';
// const WRAPPER_QUERY_ALIAS = '__nc_wrapper';
async function populatePk(model: Model, insertObj: any) {
await model.getColumns();
for (const pkCol of model.primaryKeys) {
@ -207,19 +203,16 @@ class BaseModelSqlv2 {
): Promise<any> {
const { where, fields, ...rest } = this._getListArgs(args as any);
const innerQb = this.dbDriver(this.tnPath);
innerQb.select('*');
const qb = this.dbDriver(this.tnPath);
const wrapperQb = this.dbDriver.from(innerQb.as(INNER_QUERY_ALIAS));
await this.selectObject({
qb: wrapperQb,
qb,
fieldsSet: args.fieldsSet,
viewId: this.viewId,
alias: INNER_QUERY_ALIAS,
validateFormula,
});
if (+rest?.shuffle) {
await this.shuffle({ qb: innerQb });
await this.shuffle({ qb });
}
const aliasColObjMap = await this.model.getAliasColObjMap();
@ -245,7 +238,7 @@ class BaseModelSqlv2 {
logical_op: 'and',
}),
],
innerQb,
qb,
this.dbDriver
);
@ -254,7 +247,7 @@ class BaseModelSqlv2 {
? args.sortArr
: await Sort.list({ viewId: this.viewId });
await sortV2(sorts, innerQb, this.dbDriver);
await sortV2(sorts, qb, this.dbDriver);
} else {
await conditionV2(
[
@ -269,30 +262,30 @@ class BaseModelSqlv2 {
logical_op: 'and',
}),
],
innerQb,
qb,
this.dbDriver
);
if (!sorts) sorts = args.sortArr;
await sortV2(sorts, innerQb, this.dbDriver);
await sortV2(sorts, qb, this.dbDriver);
}
// sort by primary key if not autogenerated string
// if autogenerated string sort by created_at column if present
if (this.model.primaryKey && this.model.primaryKey.ai) {
innerQb.orderBy(this.model.primaryKey.column_name);
qb.orderBy(this.model.primaryKey.column_name);
} else if (this.model.columns.find((c) => c.column_name === 'created_at')) {
innerQb.orderBy('created_at');
qb.orderBy('created_at');
}
if (!ignoreViewFilterAndSort) applyPaginate(innerQb, rest);
if (!ignoreViewFilterAndSort) applyPaginate(qb, rest);
const proto = await this.getProto();
let data;
try {
data = await this.execAndParse(wrapperQb);
data = await this.execAndParse(qb);
} catch (e) {
if (!validateFormula) {
return this.list(args, ignoreViewFilterAndSort, true);

Loading…
Cancel
Save