From 67bd3f739792f96ef5236a0ffc4a7f41ac66b861 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 21:25:42 +0800 Subject: [PATCH] refactor(nocodb): remove isEmptyList for those cases that are not required --- packages/nocodb/src/lib/models/Base.ts | 3 +- packages/nocodb/src/lib/models/Column.ts | 18 ++++-------- .../nocodb/src/lib/models/FormViewColumn.ts | 3 +- .../src/lib/models/GalleryViewColumn.ts | 3 +- .../nocodb/src/lib/models/GridViewColumn.ts | 3 +- packages/nocodb/src/lib/models/Hook.ts | 3 +- packages/nocodb/src/lib/models/HookFilter.ts | 9 ++---- .../nocodb/src/lib/models/KanbanViewColumn.ts | 3 +- .../nocodb/src/lib/models/MapViewColumn.ts | 3 +- packages/nocodb/src/lib/models/Model.ts | 29 +++++-------------- packages/nocodb/src/lib/models/Plugin.ts | 3 +- packages/nocodb/src/lib/models/Project.ts | 3 +- packages/nocodb/src/lib/models/ProjectUser.ts | 6 ++-- .../nocodb/src/lib/models/SelectOption.ts | 3 +- packages/nocodb/src/lib/models/View.ts | 12 +++----- 15 files changed, 32 insertions(+), 72 deletions(-) diff --git a/packages/nocodb/src/lib/models/Base.ts b/packages/nocodb/src/lib/models/Base.ts index 604297af54..3df992a791 100644 --- a/packages/nocodb/src/lib/models/Base.ts +++ b/packages/nocodb/src/lib/models/Base.ts @@ -154,8 +154,7 @@ export default class Base implements BaseType { args.projectId, ]); let { list: baseDataList } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !baseDataList.length) { + if (!baseDataList.length) { baseDataList = await ncMeta.metaList2( args.projectId, null, diff --git a/packages/nocodb/src/lib/models/Column.ts b/packages/nocodb/src/lib/models/Column.ts index c7e93d62a0..85610bd32c 100644 --- a/packages/nocodb/src/lib/models/Column.ts +++ b/packages/nocodb/src/lib/models/Column.ts @@ -478,8 +478,7 @@ export default class Column implements ColumnType { fk_model_id, ]); let { list: columnsList } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !columnsList.length) { + if (!columnsList.length) { columnsList = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, { condition: { fk_model_id, @@ -633,8 +632,7 @@ export default class Column implements ColumnType { { const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); let { list: lookups } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !lookups.length) { + if (!lookups.length) { lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { condition: { fk_lookup_column_id: id }, }); @@ -648,8 +646,7 @@ export default class Column implements ColumnType { { const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]); let { list: rollups } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !rollups.length) { + if (!rollups.length) { rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, { condition: { fk_rollup_column_id: id }, }); @@ -664,8 +661,7 @@ export default class Column implements ColumnType { col.fk_model_id, ]); let { list: formulaColumns } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !formulaColumns.length) { + if (!formulaColumns.length) { formulaColumns = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, { condition: { fk_model_id: col.fk_model_id, @@ -696,8 +692,7 @@ export default class Column implements ColumnType { // get lookup columns using relation and delete const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); let { list: lookups } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !lookups.length) { + if (!lookups.length) { lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { condition: { fk_relation_column_id: id }, }); @@ -711,8 +706,7 @@ export default class Column implements ColumnType { // get rollup columns using relation and delete const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]); let { list: rollups } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !rollups.length) { + if (!rollups.length) { rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, { condition: { fk_relation_column_id: id }, }); diff --git a/packages/nocodb/src/lib/models/FormViewColumn.ts b/packages/nocodb/src/lib/models/FormViewColumn.ts index 4a67c6023b..0255aa3db5 100644 --- a/packages/nocodb/src/lib/models/FormViewColumn.ts +++ b/packages/nocodb/src/lib/models/FormViewColumn.ts @@ -121,8 +121,7 @@ export default class FormViewColumn implements FormColumnType { viewId, ]); let { list: viewColumns } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !viewColumns.length) { + if (!viewColumns.length) { viewColumns = await ncMeta.metaList2( null, null, diff --git a/packages/nocodb/src/lib/models/GalleryViewColumn.ts b/packages/nocodb/src/lib/models/GalleryViewColumn.ts index 1837c334f2..d354f61606 100644 --- a/packages/nocodb/src/lib/models/GalleryViewColumn.ts +++ b/packages/nocodb/src/lib/models/GalleryViewColumn.ts @@ -101,8 +101,7 @@ export default class GalleryViewColumn { viewId, ]); let { list: views } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !views.length) { + if (!views.length) { views = await ncMeta.metaList2( null, null, diff --git a/packages/nocodb/src/lib/models/GridViewColumn.ts b/packages/nocodb/src/lib/models/GridViewColumn.ts index 5a35fbc6a6..1c5e3e1258 100644 --- a/packages/nocodb/src/lib/models/GridViewColumn.ts +++ b/packages/nocodb/src/lib/models/GridViewColumn.ts @@ -28,8 +28,7 @@ export default class GridViewColumn implements GridColumnType { viewId, ]); let { list: views } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !views.length) { + if (!views.length) { views = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, { condition: { fk_view_id: viewId, diff --git a/packages/nocodb/src/lib/models/Hook.ts b/packages/nocodb/src/lib/models/Hook.ts index 53736181a0..f01044fdcb 100644 --- a/packages/nocodb/src/lib/models/Hook.ts +++ b/packages/nocodb/src/lib/models/Hook.ts @@ -89,8 +89,7 @@ export default class Hook implements HookType { param.fk_model_id, ]); let { list: hooks } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !hooks.length) { + if (!hooks.length) { hooks = await ncMeta.metaList(null, null, MetaTable.HOOKS, { condition: { fk_model_id: param.fk_model_id, diff --git a/packages/nocodb/src/lib/models/HookFilter.ts b/packages/nocodb/src/lib/models/HookFilter.ts index 03e8e6656d..2a1610b3e8 100644 --- a/packages/nocodb/src/lib/models/HookFilter.ts +++ b/packages/nocodb/src/lib/models/HookFilter.ts @@ -209,8 +209,7 @@ export default class Filter { this.id, ]); let { list: childFilters } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !childFilters.length) { + if (!childFilters.length) { childFilters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_parent_id: this.id, @@ -247,8 +246,7 @@ export default class Filter { ): Promise { const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); let { list: filters } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !filters.length) { + if (!filters.length) { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_view_id: viewId }, }); @@ -333,8 +331,7 @@ export default class Filter { ) { const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); let { list: filterObjs } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !filterObjs.length) { + if (!filterObjs.length) { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_view_id: viewId }, }); diff --git a/packages/nocodb/src/lib/models/KanbanViewColumn.ts b/packages/nocodb/src/lib/models/KanbanViewColumn.ts index 8ebeb28298..e64b030991 100644 --- a/packages/nocodb/src/lib/models/KanbanViewColumn.ts +++ b/packages/nocodb/src/lib/models/KanbanViewColumn.ts @@ -89,8 +89,7 @@ export default class KanbanViewColumn implements KanbanColumnType { viewId, ]); let { list: views } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !views.length) { + if (!views.length) { views = await ncMeta.metaList2( null, null, diff --git a/packages/nocodb/src/lib/models/MapViewColumn.ts b/packages/nocodb/src/lib/models/MapViewColumn.ts index a14d901892..42958825c6 100644 --- a/packages/nocodb/src/lib/models/MapViewColumn.ts +++ b/packages/nocodb/src/lib/models/MapViewColumn.ts @@ -88,8 +88,7 @@ export default class MapViewColumn { viewId, ]); let { list: views } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !views.length) { + if (!views.length) { views = await ncMeta.metaList2(null, null, MetaTable.MAP_VIEW_COLUMNS, { condition: { fk_view_id: viewId, diff --git a/packages/nocodb/src/lib/models/Model.ts b/packages/nocodb/src/lib/models/Model.ts index 23523d60ad..e620f34987 100644 --- a/packages/nocodb/src/lib/models/Model.ts +++ b/packages/nocodb/src/lib/models/Model.ts @@ -160,18 +160,12 @@ export default class Model implements TableType { }, ncMeta = Noco.ncMeta ): Promise { - let cachedList; - if (base_id) { - cachedList = await NocoCache.getList(CacheScope.MODEL, [ - project_id, - base_id, - ]); - } else { - cachedList = await NocoCache.getList(CacheScope.MODEL, [project_id]); - } + const cachedList = await NocoCache.getList(CacheScope.MODEL, [ + project_id, + ]); let { list: modelList } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !modelList.length) { + + if (!modelList.length) { modelList = await ncMeta.metaList2( project_id, base_id, @@ -188,15 +182,7 @@ export default class Model implements TableType { model.meta = parseMetaProp(model); } - if (base_id) { - await NocoCache.setList( - CacheScope.MODEL, - [project_id, base_id], - modelList - ); - } else { - await NocoCache.setList(CacheScope.MODEL, [project_id], modelList); - } + await NocoCache.setList(CacheScope.MODEL, [project_id], modelList); } modelList.sort( (a, b) => @@ -221,8 +207,7 @@ export default class Model implements TableType { db_alias, ]); let { list: modelList } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !modelList.length) { + if (!modelList.length) { modelList = await ncMeta.metaList2( project_id, db_alias, diff --git a/packages/nocodb/src/lib/models/Plugin.ts b/packages/nocodb/src/lib/models/Plugin.ts index 46b322ac5a..e58f640385 100644 --- a/packages/nocodb/src/lib/models/Plugin.ts +++ b/packages/nocodb/src/lib/models/Plugin.ts @@ -45,8 +45,7 @@ export default class Plugin implements PluginType { static async list(ncMeta = Noco.ncMeta) { const cachedList = await NocoCache.getList(CacheScope.PLUGIN, []); let { list: pluginList } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !pluginList.length) { + if (!pluginList.length) { pluginList = await ncMeta.metaList2(null, null, MetaTable.PLUGIN); await NocoCache.setList(CacheScope.PLUGIN, [], pluginList); } diff --git a/packages/nocodb/src/lib/models/Project.ts b/packages/nocodb/src/lib/models/Project.ts index 2fefddd3e1..ea55a57f43 100644 --- a/packages/nocodb/src/lib/models/Project.ts +++ b/packages/nocodb/src/lib/models/Project.ts @@ -81,8 +81,7 @@ export default class Project implements ProjectType { // todo: pagination const cachedList = await NocoCache.getList(CacheScope.PROJECT, []); let { list: projectList } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !projectList.length) { + if (!projectList.length) { projectList = await ncMeta.metaList2(null, null, MetaTable.PROJECT, { xcCondition: { _or: [ diff --git a/packages/nocodb/src/lib/models/ProjectUser.ts b/packages/nocodb/src/lib/models/ProjectUser.ts index da45f180e8..437d8ccf54 100644 --- a/packages/nocodb/src/lib/models/ProjectUser.ts +++ b/packages/nocodb/src/lib/models/ProjectUser.ts @@ -191,8 +191,7 @@ export default class ProjectUser { userId, ]); let { list: cachedProjectList } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && cachedProjectList?.length) { + if (cachedProjectList?.length) { cachedProjectList = cachedProjectList.filter((p) => p.id !== projectId); await NocoCache.setList( CacheScope.USER_PROJECT, @@ -227,9 +226,8 @@ export default class ProjectUser { userId, ]); let { list: projectList } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && projectList.length) { + if (projectList.length) { return projectList; } diff --git a/packages/nocodb/src/lib/models/SelectOption.ts b/packages/nocodb/src/lib/models/SelectOption.ts index fb868ef013..86375c7f44 100644 --- a/packages/nocodb/src/lib/models/SelectOption.ts +++ b/packages/nocodb/src/lib/models/SelectOption.ts @@ -73,8 +73,7 @@ export default class SelectOption implements SelectOptionType { fk_column_id, ]); let { list: options } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !options.length) { + if (!options.length) { options = await ncMeta.metaList2( null, //, null, //model.db_alias, diff --git a/packages/nocodb/src/lib/models/View.ts b/packages/nocodb/src/lib/models/View.ts index e9f89b37e4..b57e9da3bf 100644 --- a/packages/nocodb/src/lib/models/View.ts +++ b/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) { const cachedList = await NocoCache.getList(CacheScope.VIEW, [modelId]); let { list: viewsList } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !viewsList.length) { + if (!viewsList.length) { viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { condition: { fk_model_id: modelId, @@ -1127,8 +1126,7 @@ export default class View implements ViewType { // get existing cache const cachedList = await NocoCache.getList(scope, [viewId]); const { list: dataList } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && dataList?.length) { + if (dataList?.length) { for (const o of dataList) { if (!ignoreColdIds?.length || !ignoreColdIds.includes(o.fk_column_id)) { // set data @@ -1215,7 +1213,6 @@ export default class View implements ViewType { // get existing cache const cachedList = await NocoCache.getList(scope, [viewId]); const { list: dataList } = cachedList; - const { isEmptyList } = cachedList; const colsEssentialForView = view.type === ViewTypes.MAP @@ -1224,7 +1221,7 @@ export default class View implements ViewType { const mergedIgnoreColdIds = [...ignoreColdIds, ...colsEssentialForView]; - if (!isEmptyList && dataList?.length) { + if (dataList?.length) { for (const o of dataList) { if ( !mergedIgnoreColdIds?.length || @@ -1265,8 +1262,7 @@ export default class View implements ViewType { static async shareViewList(tableId, ncMeta = Noco.ncMeta) { const cachedList = await NocoCache.getList(CacheScope.VIEW, [tableId]); let { list: sharedViews } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !sharedViews.length) { + if (!sharedViews.length) { sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { xcCondition: { fk_model_id: {