Browse Source

fix: avoid caching at the data-loader since it may leads to invalid data

- in our case we are using it just for making the data processing as batch
pull/6817/head
Pranav C 1 year ago
parent
commit
84487c5087
  1. 59
      packages/nocodb/src/db/BaseModelSqlv2.ts

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

@ -1711,7 +1711,8 @@ class BaseModelSqlv2 {
(await column.getColOptions()) as LinkToAnotherRecordColumn; (await column.getColOptions()) as LinkToAnotherRecordColumn;
if (colOptions?.type === 'hm') { if (colOptions?.type === 'hm') {
const listLoader = new DataLoader(async (ids: string[]) => { const listLoader = new DataLoader(
async (ids: string[]) => {
if (ids.length > 1) { if (ids.length > 1) {
const data = await this.multipleHmList( const data = await this.multipleHmList(
{ {
@ -1720,7 +1721,9 @@ class BaseModelSqlv2 {
}, },
(listLoader as any).args, (listLoader as any).args,
); );
return ids.map((id: string) => (data[id] ? data[id] : [])); return ids.map((id: string) =>
data[id] ? data[id] : [],
);
} else { } else {
return [ return [
await this.hmList( await this.hmList(
@ -1732,7 +1735,11 @@ class BaseModelSqlv2 {
), ),
]; ];
} }
}); },
{
cache: false,
},
);
const self: BaseModelSqlv2 = this; const self: BaseModelSqlv2 = this;
proto[ proto[
@ -1746,7 +1753,8 @@ class BaseModelSqlv2 {
); );
}; };
} else if (colOptions.type === 'mm') { } else if (colOptions.type === 'mm') {
const listLoader = new DataLoader(async (ids: string[]) => { const listLoader = new DataLoader(
async (ids: string[]) => {
if (ids?.length > 1) { if (ids?.length > 1) {
const data = await this.multipleMmList( const data = await this.multipleMmList(
{ {
@ -1768,7 +1776,11 @@ class BaseModelSqlv2 {
), ),
]; ];
} }
}); },
{
cache: false,
},
);
const self: BaseModelSqlv2 = this; const self: BaseModelSqlv2 = this;
proto[ proto[
@ -1796,7 +1808,8 @@ class BaseModelSqlv2 {
// it takes individual keys and callback is invoked with an array of values and we can get the // it takes individual keys and callback is invoked with an array of values and we can get the
// result for all those together and return the value in the same order as in the array // result for all those together and return the value in the same order as in the array
// this way all parents data extracted together // this way all parents data extracted together
const readLoader = new DataLoader(async (_ids: string[]) => { const readLoader = new DataLoader(
async (_ids: string[]) => {
// handle binary(16) foreign keys // handle binary(16) foreign keys
const ids = _ids.map((id) => { const ids = _ids.map((id) => {
if (pCol.ct !== 'binary(16)') return id; if (pCol.ct !== 'binary(16)') return id;
@ -1843,8 +1856,14 @@ class BaseModelSqlv2 {
); );
const groupedList = groupBy(data, pCol.title); const groupedList = groupBy(data, pCol.title);
return _ids.map(async (id: string) => groupedList?.[id]?.[0]); return _ids.map(
}); async (id: string) => groupedList?.[id]?.[0],
);
},
{
cache: false,
},
);
// defining BelongsTo read resolver method // defining BelongsTo read resolver method
proto[column.title] = async function (args?: any) { proto[column.title] = async function (args?: any) {
@ -4332,7 +4351,7 @@ class BaseModelSqlv2 {
} }
async addLinks({ async addLinks({
cookie: _cookie, cookie,
childIds, childIds,
colId, colId,
rowId, rowId,
@ -4348,9 +4367,12 @@ class BaseModelSqlv2 {
if (!column || !isLinksOrLTAR(column)) if (!column || !isLinksOrLTAR(column))
NcError.notFound(`Link column ${colId} not found`); NcError.notFound(`Link column ${colId} not found`);
const row = await this.dbDriver(this.tnPath) const row = await this.readByPk(
.where(await this._wherePk(rowId)) rowId,
.first(); false,
{},
{ ignoreView: true, getHiddenColumn: true },
);
// validate rowId // validate rowId
if (!row) { if (!row) {
@ -4554,9 +4576,16 @@ class BaseModelSqlv2 {
break; break;
} }
// const response = await this.readByPk(rowId); const response = await this.readByPk(
// await this.afterInsert(response, this.dbDriver, cookie); rowId,
// await this.afterAddChild(rowId, childId, cookie); false,
{},
{ ignoreView: true, getHiddenColumn: true },
);
await this.afterUpdate(row, response, this.dbDriver, cookie);
for (const childId of childIds) {
await this.afterAddChild(rowId, childId, cookie);
}
} }
async removeLinks({ async removeLinks({

Loading…
Cancel
Save