Browse Source

refactor: remove shared view meta update code

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/679/head
Pranav C 3 years ago
parent
commit
f0f62c4c39
  1. 113
      packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts

113
packages/nocodb/src/lib/noco/common/BaseApiBuilder.ts

@ -324,9 +324,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
for (const tn of [tnc, tnp]) { for (const tn of [tnc, tnp]) {
const { const {
virtualViews, virtualViews,
sharedViews, virtualViewsParamsArr
virtualViewsParamsArr,
sharedViewsParamsArr
} = await this.extractSharedAndVirtualViewsParams(tn); } = await this.extractSharedAndVirtualViewsParams(tn);
// extract alias of relation virtual column // extract alias of relation virtual column
@ -336,7 +334,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
)?._cn; )?._cn;
// virtual views param update // virtual views param update
for (const qp of [...virtualViewsParamsArr, ...sharedViewsParamsArr]) { for (const qp of virtualViewsParamsArr) {
// @ts-ignore // @ts-ignore
const { showFields = {}, fieldsOrder, extraViewParams = {} } = qp; const { showFields = {}, fieldsOrder, extraViewParams = {} } = qp;
@ -359,18 +357,14 @@ export default abstract class BaseApiBuilder<T extends Noco>
} }
await this.updateSharedAndVirtualViewsParams( await this.updateSharedAndVirtualViewsParams(
virtualViewsParamsArr, virtualViewsParamsArr,
virtualViews, virtualViews
sharedViewsParamsArr,
sharedViews
); );
} }
} }
private async updateSharedAndVirtualViewsParams( private async updateSharedAndVirtualViewsParams(
virtualViewsParamsArr: any[], virtualViewsParamsArr: any[],
virtualViews: any[], virtualViews: any[]
sharedViewsParamsArr: any[],
sharedViews: any[]
) { ) {
// update virtual views params // update virtual views params
for (let i = 0; i < virtualViewsParamsArr.length; i++) { for (let i = 0; i < virtualViewsParamsArr.length; i++) {
@ -384,19 +378,6 @@ export default abstract class BaseApiBuilder<T extends Noco>
virtualViews[i].id virtualViews[i].id
); );
} }
// update shared views params
for (let i = 0; i < sharedViewsParamsArr.length; i++) {
await this.xcMeta.metaUpdate(
this.projectId,
this.dbAlias,
'nc_shared_views',
{
query_params: JSON.stringify(sharedViewsParamsArr[i])
},
sharedViews[i].id
);
}
} }
private async extractSharedAndVirtualViewsParams(tn: string) { private async extractSharedAndVirtualViewsParams(tn: string) {
@ -411,16 +392,6 @@ export default abstract class BaseApiBuilder<T extends Noco>
} }
} }
); );
const sharedViews = await this.xcMeta.metaList(
this.projectId,
this.dbAlias,
'nc_shared_views',
{
condition: {
model_name: tn
}
}
);
const virtualViewsParamsArr = virtualViews.map(v => { const virtualViewsParamsArr = virtualViews.map(v => {
try { try {
return JSON.parse(v.query_params); return JSON.parse(v.query_params);
@ -428,18 +399,9 @@ export default abstract class BaseApiBuilder<T extends Noco>
return {}; return {};
}); });
// @ts-ignore
const sharedViewsParamsArr = sharedViews.map(v => {
try {
return JSON.parse(v.query_params);
} catch (e) {}
return {};
});
return { return {
virtualViews, virtualViews,
sharedViews, virtualViewsParamsArr
virtualViewsParamsArr,
sharedViewsParamsArr
}; };
} }
@ -592,9 +554,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
const { const {
virtualViews, virtualViews,
sharedViews, virtualViewsParamsArr
virtualViewsParamsArr,
sharedViewsParamsArr
} = await this.extractSharedAndVirtualViewsParams(tn); } = await this.extractSharedAndVirtualViewsParams(tn);
const ctx = this.generateContextForTable( const ctx = this.generateContextForTable(
@ -695,11 +655,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
); );
// virtual views param update // virtual views param update
for (const qp of [ for (const qp of [queryParams, ...virtualViewsParamsArr]) {
queryParams,
...virtualViewsParamsArr,
...sharedViewsParamsArr
]) {
if (!qp) continue; if (!qp) continue;
// @ts-ignore // @ts-ignore
const { const {
@ -860,7 +816,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
aclOper.push(async () => this.deleteColumnNameInACL(tn, column.cno)); aclOper.push(async () => this.deleteColumnNameInACL(tn, column.cno));
// virtual views param update // virtual views param update
for (const qp of [...virtualViewsParamsArr, ...sharedViewsParamsArr]) { for (const qp of [...virtualViewsParamsArr]) {
// @ts-ignore // @ts-ignore
const { const {
filters, filters,
@ -954,20 +910,6 @@ export default abstract class BaseApiBuilder<T extends Noco>
if (queryParams?.showFields) { if (queryParams?.showFields) {
queryParams.showFields[column.cno] = true; queryParams.showFields[column.cno] = true;
} }
for (const qp of sharedViewsParamsArr) {
if (!qp) continue;
// @ts-ignore
const { showFields = {}, extraViewParams = {} } = qp;
if (column.rqd) {
showFields[column.cn] = true;
extraViewParams.formParams = extraViewParams.formParams || {};
extraViewParams.formParams.fields =
extraViewParams.formParams.fields || {};
extraViewParams.formParams.fields[column.cn] = {};
}
}
} else { } else {
oldCol = oldMeta.columns.find(c => c.cn === column.cn); oldCol = oldMeta.columns.find(c => c.cn === column.cn);
newCol = newMeta.columns.find(c => c.cn === column.cn); newCol = newMeta.columns.find(c => c.cn === column.cn);
@ -979,9 +921,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
await this.updateSharedAndVirtualViewsParams( await this.updateSharedAndVirtualViewsParams(
virtualViewsParamsArr, virtualViewsParamsArr,
virtualViews, virtualViews
sharedViewsParamsArr,
sharedViews
); );
// update relation tables metadata // update relation tables metadata
@ -1370,9 +1310,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
]) { ]) {
const { const {
virtualViews, virtualViews,
sharedViews, virtualViewsParamsArr
virtualViewsParamsArr,
sharedViewsParamsArr
} = await this.extractSharedAndVirtualViewsParams(tnp); } = await this.extractSharedAndVirtualViewsParams(tnp);
const alias = this.getMeta(tnp)?.v?.find( const alias = this.getMeta(tnp)?.v?.find(
@ -1380,7 +1318,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
)?._cn; )?._cn;
// virtual views param update // virtual views param update
for (const qp of [...virtualViewsParamsArr, ...sharedViewsParamsArr]) { for (const qp of virtualViewsParamsArr) {
// @ts-ignore // @ts-ignore
const { showFields = {}, fieldsOrder, extraViewParams = {} } = qp; const { showFields = {}, fieldsOrder, extraViewParams = {} } = qp;
@ -1404,9 +1342,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
await this.updateSharedAndVirtualViewsParams( await this.updateSharedAndVirtualViewsParams(
virtualViewsParamsArr, virtualViewsParamsArr,
virtualViews, virtualViews
sharedViewsParamsArr,
sharedViews
); );
} }
} }
@ -1444,17 +1380,6 @@ export default abstract class BaseApiBuilder<T extends Noco>
} }
} }
); );
const sharedViews = await this.xcMeta.metaList(
this.projectId,
this.dbAlias,
'nc_shared_views',
{
condition: {
model_name: tn
}
}
);
const virtualViewsParamsArr = virtualViews.map(v => { const virtualViewsParamsArr = virtualViews.map(v => {
try { try {
return JSON.parse(v.query_params); return JSON.parse(v.query_params);
@ -1462,15 +1387,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
return {}; return {};
}); });
// @ts-ignore for (const qp of [...virtualViewsParamsArr]) {
const sharedViewsParamsArr = sharedViews.map(v => {
try {
return JSON.parse(v.query_params);
} catch (e) {}
return {};
});
for (const qp of [...sharedViewsParamsArr, ...virtualViewsParamsArr]) {
if (!qp) continue; if (!qp) continue;
// @ts-ignore // @ts-ignore
const { showFields = {}, fieldsOrder, extraViewParams = {} } = qp; const { showFields = {}, fieldsOrder, extraViewParams = {} } = qp;
@ -1497,9 +1414,7 @@ export default abstract class BaseApiBuilder<T extends Noco>
await this.updateSharedAndVirtualViewsParams( await this.updateSharedAndVirtualViewsParams(
virtualViewsParamsArr, virtualViewsParamsArr,
virtualViews, virtualViews
sharedViewsParamsArr,
sharedViews
); );
} }

Loading…
Cancel
Save