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. 23
      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,
]);
let { list: baseDataList } = cachedList;
const { isEmptyList } = cachedList;
if (!isEmptyList && !baseDataList.length) {
if (!baseDataList.length) {
baseDataList = await ncMeta.metaList2(
args.projectId,
null,

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

@ -478,8 +478,7 @@ export default class Column<T = any> 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<T = any> 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<T = any> 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<T = any> 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<T = any> 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<T = any> 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 },
});

3
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,

3
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,

3
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,

3
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,

9
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<FilterType> {
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 },
});

3
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,

3
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,

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

@ -160,18 +160,12 @@ export default class Model implements TableType {
},
ncMeta = Noco.ncMeta
): Promise<Model[]> {
let cachedList;
if (base_id) {
cachedList = await NocoCache.getList(CacheScope.MODEL, [
const cachedList = await NocoCache.getList(CacheScope.MODEL, [
project_id,
base_id,
]);
} else {
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,16 +182,8 @@ 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);
}
}
modelList.sort(
(a, b) =>
(a.order != null ? a.order : Infinity) -
@ -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,

3
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);
}

3
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: [

6
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;
}

3
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,

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) {
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: {

Loading…
Cancel
Save