Browse Source

refactor(nocodb): remove isEmptyList for those cases that are not required

pull/5430/head
Wing-Kam Wong 2 years ago
parent
commit
67bd3f7397
  1. 3
      packages/nocodb/src/lib/models/Base.ts
  2. 18
      packages/nocodb/src/lib/models/Column.ts
  3. 3
      packages/nocodb/src/lib/models/FormViewColumn.ts
  4. 3
      packages/nocodb/src/lib/models/GalleryViewColumn.ts
  5. 3
      packages/nocodb/src/lib/models/GridViewColumn.ts
  6. 3
      packages/nocodb/src/lib/models/Hook.ts
  7. 9
      packages/nocodb/src/lib/models/HookFilter.ts
  8. 3
      packages/nocodb/src/lib/models/KanbanViewColumn.ts
  9. 3
      packages/nocodb/src/lib/models/MapViewColumn.ts
  10. 29
      packages/nocodb/src/lib/models/Model.ts
  11. 3
      packages/nocodb/src/lib/models/Plugin.ts
  12. 3
      packages/nocodb/src/lib/models/Project.ts
  13. 6
      packages/nocodb/src/lib/models/ProjectUser.ts
  14. 3
      packages/nocodb/src/lib/models/SelectOption.ts
  15. 12
      packages/nocodb/src/lib/models/View.ts

3
packages/nocodb/src/lib/models/Base.ts

@ -154,8 +154,7 @@ export default class Base implements BaseType {
args.projectId, args.projectId,
]); ]);
let { list: baseDataList } = cachedList; let { list: baseDataList } = cachedList;
const { isEmptyList } = cachedList; if (!baseDataList.length) {
if (!isEmptyList && !baseDataList.length) {
baseDataList = await ncMeta.metaList2( baseDataList = await ncMeta.metaList2(
args.projectId, args.projectId,
null, null,

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

@ -478,8 +478,7 @@ export default class Column<T = any> implements ColumnType {
fk_model_id, fk_model_id,
]); ]);
let { list: columnsList } = cachedList; let { list: columnsList } = cachedList;
const { isEmptyList } = cachedList; if (!columnsList.length) {
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,
@ -633,8 +632,7 @@ export default class Column<T = any> implements ColumnType {
{ {
const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]);
let { list: lookups } = cachedList; let { list: lookups } = cachedList;
const { isEmptyList } = cachedList; if (!lookups.length) {
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 },
}); });
@ -648,8 +646,7 @@ export default class Column<T = any> implements ColumnType {
{ {
const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]); const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]);
let { list: rollups } = cachedList; let { list: rollups } = cachedList;
const { isEmptyList } = cachedList; if (!rollups.length) {
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 },
}); });
@ -664,8 +661,7 @@ export default class Column<T = any> implements ColumnType {
col.fk_model_id, col.fk_model_id,
]); ]);
let { list: formulaColumns } = cachedList; let { list: formulaColumns } = cachedList;
const { isEmptyList } = cachedList; if (!formulaColumns.length) {
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,
@ -696,8 +692,7 @@ export default class Column<T = any> implements ColumnType {
// get lookup columns using relation and delete // get lookup columns using relation and delete
const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]);
let { list: lookups } = cachedList; let { list: lookups } = cachedList;
const { isEmptyList } = cachedList; if (!lookups.length) {
if (!isEmptyList && !lookups.length) {
lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, {
condition: { fk_relation_column_id: id }, condition: { fk_relation_column_id: id },
}); });
@ -711,8 +706,7 @@ export default class Column<T = any> implements ColumnType {
// get rollup columns using relation and delete // get rollup columns using relation and delete
const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]); const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]);
let { list: rollups } = cachedList; let { list: rollups } = cachedList;
const { isEmptyList } = cachedList; if (!rollups.length) {
if (!isEmptyList && !rollups.length) {
rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, { rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, {
condition: { fk_relation_column_id: id }, condition: { fk_relation_column_id: id },
}); });

3
packages/nocodb/src/lib/models/FormViewColumn.ts

@ -121,8 +121,7 @@ export default class FormViewColumn implements FormColumnType {
viewId, viewId,
]); ]);
let { list: viewColumns } = cachedList; let { list: viewColumns } = cachedList;
const { isEmptyList } = cachedList; if (!viewColumns.length) {
if (!isEmptyList && !viewColumns.length) {
viewColumns = await ncMeta.metaList2( viewColumns = await ncMeta.metaList2(
null, null,
null, null,

3
packages/nocodb/src/lib/models/GalleryViewColumn.ts

@ -101,8 +101,7 @@ export default class GalleryViewColumn {
viewId, viewId,
]); ]);
let { list: views } = cachedList; let { list: views } = cachedList;
const { isEmptyList } = cachedList; if (!views.length) {
if (!isEmptyList && !views.length) {
views = await ncMeta.metaList2( views = await ncMeta.metaList2(
null, null,
null, null,

3
packages/nocodb/src/lib/models/GridViewColumn.ts

@ -28,8 +28,7 @@ export default class GridViewColumn implements GridColumnType {
viewId, viewId,
]); ]);
let { list: views } = cachedList; let { list: views } = cachedList;
const { isEmptyList } = cachedList; if (!views.length) {
if (!isEmptyList && !views.length) {
views = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, { views = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, {
condition: { condition: {
fk_view_id: viewId, fk_view_id: viewId,

3
packages/nocodb/src/lib/models/Hook.ts

@ -89,8 +89,7 @@ export default class Hook implements HookType {
param.fk_model_id, param.fk_model_id,
]); ]);
let { list: hooks } = cachedList; let { list: hooks } = cachedList;
const { isEmptyList } = cachedList; if (!hooks.length) {
if (!isEmptyList && !hooks.length) {
hooks = await ncMeta.metaList(null, null, MetaTable.HOOKS, { hooks = await ncMeta.metaList(null, null, MetaTable.HOOKS, {
condition: { condition: {
fk_model_id: param.fk_model_id, fk_model_id: param.fk_model_id,

9
packages/nocodb/src/lib/models/HookFilter.ts

@ -209,8 +209,7 @@ export default class Filter {
this.id, this.id,
]); ]);
let { list: childFilters } = cachedList; let { list: childFilters } = cachedList;
const { isEmptyList } = cachedList; if (!childFilters.length) {
if (!isEmptyList && !childFilters.length) {
childFilters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { childFilters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: { condition: {
fk_parent_id: this.id, fk_parent_id: this.id,
@ -247,8 +246,7 @@ export default class Filter {
): Promise<FilterType> { ): Promise<FilterType> {
const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]);
let { list: filters } = cachedList; let { list: filters } = cachedList;
const { isEmptyList } = cachedList; if (!filters.length) {
if (!isEmptyList && !filters.length) {
filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: { fk_view_id: viewId }, condition: { fk_view_id: viewId },
}); });
@ -333,8 +331,7 @@ export default class Filter {
) { ) {
const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]);
let { list: filterObjs } = cachedList; let { list: filterObjs } = cachedList;
const { isEmptyList } = cachedList; if (!filterObjs.length) {
if (!isEmptyList && !filterObjs.length) {
filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: { fk_view_id: viewId }, condition: { fk_view_id: viewId },
}); });

3
packages/nocodb/src/lib/models/KanbanViewColumn.ts

@ -89,8 +89,7 @@ export default class KanbanViewColumn implements KanbanColumnType {
viewId, viewId,
]); ]);
let { list: views } = cachedList; let { list: views } = cachedList;
const { isEmptyList } = cachedList; if (!views.length) {
if (!isEmptyList && !views.length) {
views = await ncMeta.metaList2( views = await ncMeta.metaList2(
null, null,
null, null,

3
packages/nocodb/src/lib/models/MapViewColumn.ts

@ -88,8 +88,7 @@ export default class MapViewColumn {
viewId, viewId,
]); ]);
let { list: views } = cachedList; let { list: views } = cachedList;
const { isEmptyList } = cachedList; if (!views.length) {
if (!isEmptyList && !views.length) {
views = await ncMeta.metaList2(null, null, MetaTable.MAP_VIEW_COLUMNS, { views = await ncMeta.metaList2(null, null, MetaTable.MAP_VIEW_COLUMNS, {
condition: { condition: {
fk_view_id: viewId, fk_view_id: viewId,

29
packages/nocodb/src/lib/models/Model.ts

@ -160,18 +160,12 @@ export default class Model implements TableType {
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<Model[]> { ): Promise<Model[]> {
let cachedList; const cachedList = await NocoCache.getList(CacheScope.MODEL, [
if (base_id) { project_id,
cachedList = await NocoCache.getList(CacheScope.MODEL, [ ]);
project_id,
base_id,
]);
} else {
cachedList = await NocoCache.getList(CacheScope.MODEL, [project_id]);
}
let { list: modelList } = cachedList; let { list: modelList } = cachedList;
const { isEmptyList } = cachedList;
if (!isEmptyList && !modelList.length) { if (!modelList.length) {
modelList = await ncMeta.metaList2( modelList = await ncMeta.metaList2(
project_id, project_id,
base_id, base_id,
@ -188,15 +182,7 @@ export default class Model implements TableType {
model.meta = parseMetaProp(model); model.meta = parseMetaProp(model);
} }
if (base_id) { await NocoCache.setList(CacheScope.MODEL, [project_id], modelList);
await NocoCache.setList(
CacheScope.MODEL,
[project_id, base_id],
modelList
);
} else {
await NocoCache.setList(CacheScope.MODEL, [project_id], modelList);
}
} }
modelList.sort( modelList.sort(
(a, b) => (a, b) =>
@ -221,8 +207,7 @@ export default class Model implements TableType {
db_alias, db_alias,
]); ]);
let { list: modelList } = cachedList; let { list: modelList } = cachedList;
const { isEmptyList } = cachedList; if (!modelList.length) {
if (!isEmptyList && !modelList.length) {
modelList = await ncMeta.metaList2( modelList = await ncMeta.metaList2(
project_id, project_id,
db_alias, db_alias,

3
packages/nocodb/src/lib/models/Plugin.ts

@ -45,8 +45,7 @@ export default class Plugin implements PluginType {
static async list(ncMeta = Noco.ncMeta) { static async list(ncMeta = Noco.ncMeta) {
const cachedList = await NocoCache.getList(CacheScope.PLUGIN, []); const cachedList = await NocoCache.getList(CacheScope.PLUGIN, []);
let { list: pluginList } = cachedList; let { list: pluginList } = cachedList;
const { isEmptyList } = cachedList; if (!pluginList.length) {
if (!isEmptyList && !pluginList.length) {
pluginList = await ncMeta.metaList2(null, null, MetaTable.PLUGIN); pluginList = await ncMeta.metaList2(null, null, MetaTable.PLUGIN);
await NocoCache.setList(CacheScope.PLUGIN, [], pluginList); await NocoCache.setList(CacheScope.PLUGIN, [], pluginList);
} }

3
packages/nocodb/src/lib/models/Project.ts

@ -81,8 +81,7 @@ export default class Project implements ProjectType {
// todo: pagination // todo: pagination
const cachedList = await NocoCache.getList(CacheScope.PROJECT, []); const cachedList = await NocoCache.getList(CacheScope.PROJECT, []);
let { list: projectList } = cachedList; let { list: projectList } = cachedList;
const { isEmptyList } = cachedList; if (!projectList.length) {
if (!isEmptyList && !projectList.length) {
projectList = await ncMeta.metaList2(null, null, MetaTable.PROJECT, { projectList = await ncMeta.metaList2(null, null, MetaTable.PROJECT, {
xcCondition: { xcCondition: {
_or: [ _or: [

6
packages/nocodb/src/lib/models/ProjectUser.ts

@ -191,8 +191,7 @@ export default class ProjectUser {
userId, userId,
]); ]);
let { list: cachedProjectList } = cachedList; let { list: cachedProjectList } = cachedList;
const { isEmptyList } = cachedList; if (cachedProjectList?.length) {
if (!isEmptyList && cachedProjectList?.length) {
cachedProjectList = cachedProjectList.filter((p) => p.id !== projectId); cachedProjectList = cachedProjectList.filter((p) => p.id !== projectId);
await NocoCache.setList( await NocoCache.setList(
CacheScope.USER_PROJECT, CacheScope.USER_PROJECT,
@ -227,9 +226,8 @@ export default class ProjectUser {
userId, userId,
]); ]);
let { list: projectList } = cachedList; let { list: projectList } = cachedList;
const { isEmptyList } = cachedList;
if (!isEmptyList && projectList.length) { if (projectList.length) {
return projectList; return projectList;
} }

3
packages/nocodb/src/lib/models/SelectOption.ts

@ -73,8 +73,7 @@ export default class SelectOption implements SelectOptionType {
fk_column_id, fk_column_id,
]); ]);
let { list: options } = cachedList; let { list: options } = cachedList;
const { isEmptyList } = cachedList; if (!options.length) {
if (!isEmptyList && !options.length) {
options = await ncMeta.metaList2( options = await ncMeta.metaList2(
null, //, null, //,
null, //model.db_alias, null, //model.db_alias,

12
packages/nocodb/src/lib/models/View.ts

@ -207,8 +207,7 @@ export default class View implements ViewType {
public static async list(modelId: string, ncMeta = Noco.ncMeta) { public static async list(modelId: string, ncMeta = Noco.ncMeta) {
const cachedList = await NocoCache.getList(CacheScope.VIEW, [modelId]); const cachedList = await NocoCache.getList(CacheScope.VIEW, [modelId]);
let { list: viewsList } = cachedList; let { list: viewsList } = cachedList;
const { isEmptyList } = cachedList; if (!viewsList.length) {
if (!isEmptyList && !viewsList.length) {
viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, {
condition: { condition: {
fk_model_id: modelId, fk_model_id: modelId,
@ -1127,8 +1126,7 @@ export default class View implements ViewType {
// get existing cache // get existing cache
const cachedList = await NocoCache.getList(scope, [viewId]); const cachedList = await NocoCache.getList(scope, [viewId]);
const { list: dataList } = cachedList; const { list: dataList } = cachedList;
const { isEmptyList } = cachedList; if (dataList?.length) {
if (!isEmptyList && dataList?.length) {
for (const o of dataList) { for (const o of dataList) {
if (!ignoreColdIds?.length || !ignoreColdIds.includes(o.fk_column_id)) { if (!ignoreColdIds?.length || !ignoreColdIds.includes(o.fk_column_id)) {
// set data // set data
@ -1215,7 +1213,6 @@ export default class View implements ViewType {
// get existing cache // get existing cache
const cachedList = await NocoCache.getList(scope, [viewId]); const cachedList = await NocoCache.getList(scope, [viewId]);
const { list: dataList } = cachedList; const { list: dataList } = cachedList;
const { isEmptyList } = cachedList;
const colsEssentialForView = const colsEssentialForView =
view.type === ViewTypes.MAP view.type === ViewTypes.MAP
@ -1224,7 +1221,7 @@ export default class View implements ViewType {
const mergedIgnoreColdIds = [...ignoreColdIds, ...colsEssentialForView]; const mergedIgnoreColdIds = [...ignoreColdIds, ...colsEssentialForView];
if (!isEmptyList && dataList?.length) { if (dataList?.length) {
for (const o of dataList) { for (const o of dataList) {
if ( if (
!mergedIgnoreColdIds?.length || !mergedIgnoreColdIds?.length ||
@ -1265,8 +1262,7 @@ export default class View implements ViewType {
static async shareViewList(tableId, ncMeta = Noco.ncMeta) { static async shareViewList(tableId, ncMeta = Noco.ncMeta) {
const cachedList = await NocoCache.getList(CacheScope.VIEW, [tableId]); const cachedList = await NocoCache.getList(CacheScope.VIEW, [tableId]);
let { list: sharedViews } = cachedList; let { list: sharedViews } = cachedList;
const { isEmptyList } = cachedList; if (!sharedViews.length) {
if (!isEmptyList && !sharedViews.length) {
sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEWS, {
xcCondition: { xcCondition: {
fk_model_id: { fk_model_id: {

Loading…
Cancel
Save