Browse Source

Nc fix/insert issue (#7947)

* fix: use  optimized query reader for post insert read

* fix: use optimised query for read before delete

* fix: add async
pull/7956/head
Pranav C 8 months ago committed by GitHub
parent
commit
11fe984a67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 62
      packages/nocodb/src/db/BaseModelSqlv2.ts

62
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -2813,13 +2813,15 @@ class BaseModelSqlv2 {
async delByPk(id, _trx?, cookie?) {
let trx: Knex.Transaction = _trx;
try {
const source = await Source.get(this.model.source_id);
// retrieve data for handling params in hook
const data = await this.readByPk(
id,
false,
{},
{ ignoreView: true, getHiddenColumn: true },
);
const data = await this.readRecord({
idOrRecord: id,
validateFormula: false,
ignoreView: true,
getHiddenColumn: true,
source,
});
await this.beforeDelete(id, trx, cookie);
const execQueries: ((trx: Knex.Transaction) => Promise<any>)[] = [];
@ -3056,9 +3058,31 @@ class BaseModelSqlv2 {
return this.dbDriver.clientType();
}
public async readRecord(params: {
idOrRecord: string | Record<string, any>;
fieldsSet?: Set<string>;
ignoreView?: boolean;
getHiddenColumn?: boolean;
validateFormula?: boolean;
source: Source;
disableOptimization?: boolean;
view?: View;
}): Promise<any> {
return this.readByPk(
params.idOrRecord,
false,
{},
{
ignoreView: params.ignoreView,
getHiddenColumn: params.getHiddenColumn,
},
);
}
async nestedInsert(data, _trx = null, cookie?) {
// const driver = trx ? trx : await this.dbDriver.transaction();
try {
const source = await Source.get(this.model.source_id);
await populatePk(this.model, data);
const insertObj = await this.model.mapAliasToColumn(
data,
@ -3102,12 +3126,13 @@ class BaseModelSqlv2 {
// handle if autogenerated primary key is used
if (ag) {
if (!response) await this.execAndParse(query);
response = await this.readByPk(
insertObj[ag.column_name],
false,
{},
{ ignoreView: true, getHiddenColumn: true },
);
response = await this.readRecord({
idOrRecord: insertObj[ag.column_name],
ignoreView: true,
getHiddenColumn: true,
validateFormula: false,
source,
});
} else if (
!response ||
(typeof response?.[0] !== 'object' && response?.[0] !== null)
@ -3166,12 +3191,13 @@ class BaseModelSqlv2 {
await Promise.all(postInsertOps.map((f) => f(rowId)));
if (rowId !== null && rowId !== undefined) {
response = await this.readByPk(
rowId,
false,
{},
{ ignoreView: true, getHiddenColumn: true },
);
response = await this.readRecord({
idOrRecord: rowId,
validateFormula: false,
ignoreView: true,
getHiddenColumn: true,
source,
});
}
await this.afterInsert(response, this.dbDriver, cookie);

Loading…
Cancel
Save