Browse Source

refactor(nocodb): adopt getList new format in Column.ts

pull/5430/head
Wing-Kam Wong 2 years ago
parent
commit
98029f077b
  1. 82
      packages/nocodb/src/lib/models/Column.ts

82
packages/nocodb/src/lib/models/Column.ts

@ -474,8 +474,12 @@ export default class Column<T = any> implements ColumnType {
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<Column[]> { ): Promise<Column[]> {
let columnsList = await NocoCache.getList(CacheScope.COLUMN, [fk_model_id]); const cachedList = await NocoCache.getList(CacheScope.COLUMN, [
if (!columnsList.length) { fk_model_id,
]);
let { list: columnsList } = cachedList;
const { isEmptyList } = cachedList;
if (!isEmptyList && !columnsList.length) {
columnsList = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, { columnsList = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, {
condition: { condition: {
fk_model_id, fk_model_id,
@ -627,8 +631,10 @@ export default class Column<T = any> implements ColumnType {
// get lookup columns and delete // get lookup columns and delete
{ {
let lookups = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]);
if (!lookups.length) { let { list: lookups } = cachedList;
const { isEmptyList } = cachedList;
if (!isEmptyList && !lookups.length) {
lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, {
condition: { fk_lookup_column_id: id }, condition: { fk_lookup_column_id: id },
}); });
@ -640,8 +646,10 @@ export default class Column<T = any> implements ColumnType {
// get rollup column and delete // get rollup column and delete
{ {
let rollups = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]); const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]);
if (!rollups.length) { let { list: rollups } = cachedList;
const { isEmptyList } = cachedList;
if (!isEmptyList && !rollups.length) {
rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, { rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, {
condition: { fk_rollup_column_id: id }, condition: { fk_rollup_column_id: id },
}); });
@ -652,10 +660,12 @@ export default class Column<T = any> implements ColumnType {
} }
{ {
let formulaColumns = await NocoCache.getList(CacheScope.COLUMN, [ const cachedList = await NocoCache.getList(CacheScope.COLUMN, [
col.fk_model_id, col.fk_model_id,
]); ]);
if (!formulaColumns.length) { let { list: formulaColumns } = cachedList;
const { isEmptyList } = cachedList;
if (!isEmptyList && !formulaColumns.length) {
formulaColumns = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, { formulaColumns = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, {
condition: { condition: {
fk_model_id: col.fk_model_id, fk_model_id: col.fk_model_id,
@ -682,33 +692,43 @@ export default class Column<T = any> implements ColumnType {
// if relation column check lookup and rollup and delete // if relation column check lookup and rollup and delete
if (col.uidt === UITypes.LinkToAnotherRecord) { if (col.uidt === UITypes.LinkToAnotherRecord) {
// get lookup columns using relation and delete {
let lookups = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); // get lookup columns using relation and delete
if (!lookups.length) { const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]);
lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { let { list: lookups } = cachedList;
condition: { fk_relation_column_id: id }, const { isEmptyList } = cachedList;
}); if (!isEmptyList && !lookups.length) {
} lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, {
for (const lookup of lookups) { condition: { fk_relation_column_id: id },
await Column.delete(lookup.fk_column_id, ncMeta); });
}
for (const lookup of lookups) {
await Column.delete(lookup.fk_column_id, ncMeta);
}
} }
// get rollup columns using relation and delete {
let rollups = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]); // get rollup columns using relation and delete
if (!rollups.length) { const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]);
rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, { let { list: rollups } = cachedList;
condition: { fk_relation_column_id: id }, const { isEmptyList } = cachedList;
}); if (!isEmptyList && !rollups.length) {
} rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, {
for (const rollup of rollups) { condition: { fk_relation_column_id: id },
await Column.delete(rollup.fk_column_id, ncMeta); });
}
for (const rollup of rollups) {
await Column.delete(rollup.fk_column_id, ncMeta);
}
} }
} }
// delete sorts // delete sorts
{ {
let sorts = await NocoCache.getList(CacheScope.SORT, [id]); const cachedList = await NocoCache.getList(CacheScope.SORT, [id]);
if (!sorts.length) { let { list: sorts } = cachedList;
const { isEmptyList } = cachedList;
if (!isEmptyList && !sorts.length) {
sorts = await ncMeta.metaList2(null, null, MetaTable.SORT, { sorts = await ncMeta.metaList2(null, null, MetaTable.SORT, {
condition: { condition: {
fk_column_id: id, fk_column_id: id,
@ -721,8 +741,10 @@ export default class Column<T = any> implements ColumnType {
} }
// delete filters // delete filters
{ {
let filters = await NocoCache.getList(CacheScope.FILTER_EXP, [id]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [id]);
if (!filters.length) { let { list: filters } = cachedList;
const { isEmptyList } = cachedList;
if (!isEmptyList && !filters.length) {
filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: { condition: {
fk_column_id: id, fk_column_id: id,

Loading…
Cancel
Save