From 252d83272b2c933cfbda03229f46992eb4cd51a6 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 6 Apr 2023 21:06:26 +0800 Subject: [PATCH 01/37] feat(nocodb): revise cache getList response --- packages/nocodb/src/lib/cache/CacheMgr.ts | 8 +++++++- packages/nocodb/src/lib/cache/NocoCache.ts | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/nocodb/src/lib/cache/CacheMgr.ts b/packages/nocodb/src/lib/cache/CacheMgr.ts index 258b1ff090..4554072a7a 100644 --- a/packages/nocodb/src/lib/cache/CacheMgr.ts +++ b/packages/nocodb/src/lib/cache/CacheMgr.ts @@ -4,7 +4,13 @@ export default abstract class CacheMgr { public abstract del(key: string): Promise; public abstract getAll(pattern: string): Promise; public abstract delAll(scope: string, pattern: string): Promise; - public abstract getList(scope: string, list: string[]): Promise; + public abstract getList( + scope: string, + list: string[] + ): Promise<{ + list: any[]; + isEmptyList: boolean; + }>; public abstract setList( scope: string, subListKeys: string[], diff --git a/packages/nocodb/src/lib/cache/NocoCache.ts b/packages/nocodb/src/lib/cache/NocoCache.ts index 381760fef0..f00183edc1 100644 --- a/packages/nocodb/src/lib/cache/NocoCache.ts +++ b/packages/nocodb/src/lib/cache/NocoCache.ts @@ -56,8 +56,15 @@ export default class NocoCache { public static async getList( scope: string, subKeys: string[] - ): Promise { - if (this.cacheDisabled) return Promise.resolve([]); + ): Promise<{ + list: any[]; + isEmptyList: boolean; + }> { + if (this.cacheDisabled) + return Promise.resolve({ + list: [], + isEmptyList: true, + }); return this.client.getList(scope, subKeys); } From 61e1c3b4b66328b87e9db8f3ac534573248c8b74 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 6 Apr 2023 21:08:54 +0800 Subject: [PATCH 02/37] feat(nocodb): revise cache getList logic --- .../nocodb/src/lib/cache/RedisCacheMgr.ts | 27 ++++++++++++----- .../nocodb/src/lib/cache/RedisMockCacheMgr.ts | 29 +++++++++++++------ 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts index b8deaae118..b8a457c3c9 100644 --- a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts @@ -44,7 +44,7 @@ export default class RedisCacheMgr extends CacheMgr { async get(key: string, type: string, config?: any): Promise { log(`RedisCacheMgr::get: getting key ${key} with type ${type}`); if (type === CacheGetType.TYPE_ARRAY) { - return this.client.smembers(key); + return await this.client.smembers(key); } else if (type === CacheGetType.TYPE_OBJECT) { const res = await this.client.get(key); try { @@ -114,7 +114,13 @@ export default class RedisCacheMgr extends CacheMgr { ); } - async getList(scope: string, subKeys: string[]): Promise { + async getList( + scope: string, + subKeys: string[] + ): Promise<{ + list: any[]; + isEmptyList: boolean; + }> { // remove null from arrays subKeys = subKeys.filter((k) => k); // e.g. key = nc:::::list @@ -125,9 +131,17 @@ export default class RedisCacheMgr extends CacheMgr { // e.g. arr = ["nc:::", "nc:::"] const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; log(`RedisCacheMgr::getList: getting list with key ${key}`); - return Promise.all( - arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) - ); + let list: any[] = []; + const isEmptyList = arr[0] === 'NONE'; + if (!isEmptyList) { + list = await Promise.all( + arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) + ); + } + return { + list, + isEmptyList, + }; } async setList( @@ -144,8 +158,7 @@ export default class RedisCacheMgr extends CacheMgr { ? `${this.prefix}:${scope}:list` : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; if (!list.length) { - log(`RedisCacheMgr::setList: List is empty for ${listKey}. Skipping ...`); - return Promise.resolve(true); + return this.set(listKey, ['NONE']); } // fetch existing list const listOfGetKeys = diff --git a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts index a06ddd9fe5..53d084abab 100644 --- a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts @@ -43,7 +43,7 @@ export default class RedisMockCacheMgr extends CacheMgr { async get(key: string, type: string, config?: any): Promise { log(`RedisMockCacheMgr::get: getting key ${key} with type ${type}`); if (type === CacheGetType.TYPE_ARRAY) { - return this.client.smembers(key); + return await this.client.smembers(key); } else if (type === CacheGetType.TYPE_OBJECT) { const res = await this.client.get(key); try { @@ -114,7 +114,13 @@ export default class RedisMockCacheMgr extends CacheMgr { ); } - async getList(scope: string, subKeys: string[]): Promise { + async getList( + scope: string, + subKeys: string[] + ): Promise<{ + list: any[]; + isEmptyList: boolean; + }> { // remove null from arrays subKeys = subKeys.filter((k) => k); // e.g. key = nc:::::list @@ -125,9 +131,17 @@ export default class RedisMockCacheMgr extends CacheMgr { // e.g. arr = ["nc:::", "nc:::"] const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; log(`RedisMockCacheMgr::getList: getting list with key ${key}`); - return Promise.all( - arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) - ); + let list: any[] = []; + const isEmptyList = arr[0] === 'NONE'; + if (!isEmptyList) { + list = await Promise.all( + arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) + ); + } + return { + list, + isEmptyList, + }; } async setList( @@ -144,10 +158,7 @@ export default class RedisMockCacheMgr extends CacheMgr { ? `${this.prefix}:${scope}:list` : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; if (!list.length) { - log( - `RedisMockCacheMgr::setList: List is empty for ${listKey}. Skipping ...` - ); - return Promise.resolve(true); + return this.set(listKey, ['NONE']); } // fetch existing list const listOfGetKeys = From 59c2accf8c7e0f449c828cdf3940f1f2b0152794 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 6 Apr 2023 21:12:40 +0800 Subject: [PATCH 03/37] refactor(nocodb): adopt getList new format in Filter.ts --- packages/nocodb/src/lib/models/Filter.ts | 38 ++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/packages/nocodb/src/lib/models/Filter.ts b/packages/nocodb/src/lib/models/Filter.ts index abb9b21b1a..aa6afd20c0 100644 --- a/packages/nocodb/src/lib/models/Filter.ts +++ b/packages/nocodb/src/lib/models/Filter.ts @@ -326,10 +326,12 @@ export default class Filter implements FilterType { public async getChildren(ncMeta = Noco.ncMeta): Promise { if (this.children) return this.children; if (!this.is_group) return null; - let childFilters = await NocoCache.getList(CacheScope.FILTER_EXP, [ + const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [ this.id, ]); - if (!childFilters.length) { + let { list: childFilters } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !childFilters.length) { childFilters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_parent_id: this.id, @@ -369,10 +371,12 @@ export default class Filter implements FilterType { }, ncMeta = Noco.ncMeta ): Promise { - let filters = await NocoCache.getList(CacheScope.FILTER_EXP, [ + const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [ viewId || hookId, ]); - if (!filters.length) { + let { list: filters } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !filters.length) { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: viewId ? { fk_view_id: viewId } : { fk_hook_id: hookId }, orderBy: { @@ -480,8 +484,10 @@ export default class Filter implements FilterType { { viewId }: { viewId: any }, ncMeta = Noco.ncMeta ) { - let filterObjs = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); - if (!filterObjs.length) { + const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); + let { list: filterObjs } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !filterObjs.length) { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_view_id: viewId }, orderBy: { @@ -499,8 +505,10 @@ export default class Filter implements FilterType { { hookId }: { hookId: any }, ncMeta = Noco.ncMeta ) { - let filterObjs = await NocoCache.getList(CacheScope.FILTER_EXP, [hookId]); - if (!filterObjs.length) { + const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [hookId]); + let { list: filterObjs } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !filterObjs.length) { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_hook_id: hookId }, orderBy: { @@ -520,8 +528,12 @@ export default class Filter implements FilterType { }, ncMeta = Noco.ncMeta ) { - let filterObjs = await NocoCache.getList(CacheScope.FILTER_EXP, [parentId]); - if (!filterObjs.length) { + const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [ + parentId, + ]); + let { list: filterObjs } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !filterObjs.length) { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_parent_id: parentId, @@ -546,11 +558,13 @@ export default class Filter implements FilterType { }, ncMeta = Noco.ncMeta ) { - let filterObjs = await NocoCache.getList(CacheScope.FILTER_EXP, [ + const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [ hookId, parentId, ]); - if (!filterObjs.length) { + let { list: filterObjs } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !filterObjs.length) { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_parent_id: parentId, From 0b952cebda482b78c4ea35b102c3d7a492a777dd Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 10 Apr 2023 16:37:37 +0800 Subject: [PATCH 04/37] refactor(nocodb): adopt getList new format in Base.ts --- packages/nocodb/src/lib/models/Base.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/models/Base.ts b/packages/nocodb/src/lib/models/Base.ts index 709f6598c0..604297af54 100644 --- a/packages/nocodb/src/lib/models/Base.ts +++ b/packages/nocodb/src/lib/models/Base.ts @@ -150,10 +150,12 @@ export default class Base implements BaseType { args: { projectId: string }, ncMeta = Noco.ncMeta ): Promise { - let baseDataList = await NocoCache.getList(CacheScope.BASE, [ + const cachedList = await NocoCache.getList(CacheScope.BASE, [ args.projectId, ]); - if (!baseDataList.length) { + let { list: baseDataList } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !baseDataList.length) { baseDataList = await ncMeta.metaList2( args.projectId, null, From 98029f077bd3a1d27d9828ad1cd63ac8045cfc34 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 10 Apr 2023 16:38:06 +0800 Subject: [PATCH 05/37] refactor(nocodb): adopt getList new format in Column.ts --- packages/nocodb/src/lib/models/Column.ts | 82 +++++++++++++++--------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/packages/nocodb/src/lib/models/Column.ts b/packages/nocodb/src/lib/models/Column.ts index 5550142f2c..c7e93d62a0 100644 --- a/packages/nocodb/src/lib/models/Column.ts +++ b/packages/nocodb/src/lib/models/Column.ts @@ -474,8 +474,12 @@ export default class Column implements ColumnType { }, ncMeta = Noco.ncMeta ): Promise { - let columnsList = await NocoCache.getList(CacheScope.COLUMN, [fk_model_id]); - if (!columnsList.length) { + const cachedList = await NocoCache.getList(CacheScope.COLUMN, [ + fk_model_id, + ]); + let { list: columnsList } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !columnsList.length) { columnsList = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, { condition: { fk_model_id, @@ -627,8 +631,10 @@ export default class Column implements ColumnType { // get lookup columns and delete { - let lookups = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); - if (!lookups.length) { + const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); + let { list: lookups } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !lookups.length) { lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { condition: { fk_lookup_column_id: id }, }); @@ -640,8 +646,10 @@ export default class Column implements ColumnType { // get rollup column and delete { - let rollups = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]); - if (!rollups.length) { + const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]); + let { list: rollups } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !rollups.length) { rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, { condition: { fk_rollup_column_id: id }, }); @@ -652,10 +660,12 @@ export default class Column implements ColumnType { } { - let formulaColumns = await NocoCache.getList(CacheScope.COLUMN, [ + const cachedList = await NocoCache.getList(CacheScope.COLUMN, [ 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, { condition: { fk_model_id: col.fk_model_id, @@ -682,33 +692,43 @@ export default class Column implements ColumnType { // if relation column check lookup and rollup and delete if (col.uidt === UITypes.LinkToAnotherRecord) { - // get lookup columns using relation and delete - let lookups = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); - if (!lookups.length) { - lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { - condition: { fk_relation_column_id: id }, - }); - } - for (const lookup of lookups) { - await Column.delete(lookup.fk_column_id, ncMeta); + { + // 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) { + lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { + condition: { fk_relation_column_id: id }, + }); + } + 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]); - if (!rollups.length) { - rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, { - condition: { fk_relation_column_id: id }, - }); - } - for (const rollup of rollups) { - await Column.delete(rollup.fk_column_id, ncMeta); + { + // 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) { + rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, { + condition: { fk_relation_column_id: id }, + }); + } + for (const rollup of rollups) { + await Column.delete(rollup.fk_column_id, ncMeta); + } } } // delete sorts { - let sorts = await NocoCache.getList(CacheScope.SORT, [id]); - if (!sorts.length) { + const cachedList = await NocoCache.getList(CacheScope.SORT, [id]); + let { list: sorts } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !sorts.length) { sorts = await ncMeta.metaList2(null, null, MetaTable.SORT, { condition: { fk_column_id: id, @@ -721,8 +741,10 @@ export default class Column implements ColumnType { } // delete filters { - let filters = await NocoCache.getList(CacheScope.FILTER_EXP, [id]); - if (!filters.length) { + const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [id]); + let { list: filters } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !filters.length) { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_column_id: id, From fda8d6753292ecfe3b41ddf1a06ad88a17e0a9eb Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 10 Apr 2023 16:38:19 +0800 Subject: [PATCH 06/37] refactor(nocodb): adopt getList new format in FormViewColumn.ts --- .../nocodb/src/lib/models/FormViewColumn.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/nocodb/src/lib/models/FormViewColumn.ts b/packages/nocodb/src/lib/models/FormViewColumn.ts index 69795004d1..37918c281b 100644 --- a/packages/nocodb/src/lib/models/FormViewColumn.ts +++ b/packages/nocodb/src/lib/models/FormViewColumn.ts @@ -100,13 +100,11 @@ export default class FormViewColumn implements FormColumnType { await NocoCache.set(`${CacheScope.FORM_VIEW_COLUMN}:${fk_column_id}`, id); // if cache is not present skip pushing it into the list to avoid unexpected behaviour - if ( - ( - await NocoCache.getList(CacheScope.FORM_VIEW_COLUMN, [ - column.fk_view_id, - ]) - )?.length - ) + const { list } = await NocoCache.getList(CacheScope.FORM_VIEW_COLUMN, [ + column.fk_view_id, + ]) + + if (list.length) await NocoCache.appendToList( CacheScope.FORM_VIEW_COLUMN, [column.fk_view_id], @@ -119,10 +117,12 @@ export default class FormViewColumn implements FormColumnType { viewId: string, ncMeta = Noco.ncMeta ): Promise { - let viewColumns = await NocoCache.getList(CacheScope.FORM_VIEW_COLUMN, [ + const cachedList = await NocoCache.getList(CacheScope.FORM_VIEW_COLUMN, [ viewId, ]); - if (!viewColumns.length) { + let { list: viewColumns } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !viewColumns.length) { viewColumns = await ncMeta.metaList2( null, null, From c8985680e2beb9853b97c5cf62a14456f0d8bd72 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 10 Apr 2023 16:39:54 +0800 Subject: [PATCH 07/37] fix(nocodb): add ? to list --- packages/nocodb/src/lib/models/FormViewColumn.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nocodb/src/lib/models/FormViewColumn.ts b/packages/nocodb/src/lib/models/FormViewColumn.ts index 37918c281b..790036fb06 100644 --- a/packages/nocodb/src/lib/models/FormViewColumn.ts +++ b/packages/nocodb/src/lib/models/FormViewColumn.ts @@ -104,7 +104,7 @@ export default class FormViewColumn implements FormColumnType { column.fk_view_id, ]) - if (list.length) + if (list?.length) await NocoCache.appendToList( CacheScope.FORM_VIEW_COLUMN, [column.fk_view_id], From 36300a235e088d7bce6b6bf7dbaa8d3c375532d3 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 10 Apr 2023 17:23:49 +0800 Subject: [PATCH 08/37] refactor(nocodb): adopt getList new format in GalleryViewColumn.ts --- packages/nocodb/src/lib/models/GalleryViewColumn.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/nocodb/src/lib/models/GalleryViewColumn.ts b/packages/nocodb/src/lib/models/GalleryViewColumn.ts index 6e744e0281..8ddf12b6e1 100644 --- a/packages/nocodb/src/lib/models/GalleryViewColumn.ts +++ b/packages/nocodb/src/lib/models/GalleryViewColumn.ts @@ -79,13 +79,11 @@ export default class GalleryViewColumn { ); // if cache is not present skip pushing it into the list to avoid unexpected behaviour - if ( - ( - await NocoCache.getList(CacheScope.GALLERY_VIEW_COLUMN, [ - column.fk_view_id, - ]) - )?.length - ) + const { list } = await NocoCache.getList(CacheScope.GALLERY_VIEW_COLUMN, [ + column.fk_view_id, + ]); + + if (list?.length) await NocoCache.appendToList( CacheScope.GALLERY_VIEW_COLUMN, [column.fk_view_id], From 83b724f2cd05b688b5220610857a37511186c12c Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 10 Apr 2023 17:24:07 +0800 Subject: [PATCH 09/37] refactor(nocodb): adopt getList new format in GridViewColumn.ts --- .../nocodb/src/lib/models/GridViewColumn.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/nocodb/src/lib/models/GridViewColumn.ts b/packages/nocodb/src/lib/models/GridViewColumn.ts index 1c81d33e34..5a35fbc6a6 100644 --- a/packages/nocodb/src/lib/models/GridViewColumn.ts +++ b/packages/nocodb/src/lib/models/GridViewColumn.ts @@ -24,8 +24,12 @@ export default class GridViewColumn implements GridColumnType { viewId: string, ncMeta = Noco.ncMeta ): Promise { - let views = await NocoCache.getList(CacheScope.GRID_VIEW_COLUMN, [viewId]); - if (!views.length) { + const cachedList = await NocoCache.getList(CacheScope.GRID_VIEW_COLUMN, [ + viewId, + ]); + let { list: views } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !views.length) { views = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, { condition: { fk_view_id: viewId, @@ -99,13 +103,10 @@ export default class GridViewColumn implements GridColumnType { await NocoCache.set(`${CacheScope.GRID_VIEW_COLUMN}:${fk_column_id}`, id); // if cache is not present skip pushing it into the list to avoid unexpected behaviour - if ( - ( - await NocoCache.getList(CacheScope.GRID_VIEW_COLUMN, [ - column.fk_view_id, - ]) - )?.length - ) + const { list } = await NocoCache.getList(CacheScope.GRID_VIEW_COLUMN, [ + column.fk_view_id, + ]); + if (list.length) await NocoCache.appendToList( CacheScope.GRID_VIEW_COLUMN, [column.fk_view_id], From 7b70191f1b304a1e327f88f6cbb78c28dbdd7751 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 10 Apr 2023 17:24:23 +0800 Subject: [PATCH 10/37] refactor(nocodb): adopt getList new format in Hook.ts --- packages/nocodb/src/lib/models/Hook.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/models/Hook.ts b/packages/nocodb/src/lib/models/Hook.ts index 1b0e0761a3..53736181a0 100644 --- a/packages/nocodb/src/lib/models/Hook.ts +++ b/packages/nocodb/src/lib/models/Hook.ts @@ -85,8 +85,12 @@ export default class Hook implements HookType { }, ncMeta = Noco.ncMeta ) { - let hooks = await NocoCache.getList(CacheScope.HOOK, [param.fk_model_id]); - if (!hooks.length) { + const cachedList = await NocoCache.getList(CacheScope.HOOK, [ + param.fk_model_id, + ]); + let { list: hooks } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !hooks.length) { hooks = await ncMeta.metaList(null, null, MetaTable.HOOKS, { condition: { fk_model_id: param.fk_model_id, From 649e7cc15ee6bde7208f4f0665731b0e6a7737af Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 10 Apr 2023 17:24:42 +0800 Subject: [PATCH 11/37] refactor(nocodb): adopt getList new format in HookFilter.ts --- packages/nocodb/src/lib/models/HookFilter.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/nocodb/src/lib/models/HookFilter.ts b/packages/nocodb/src/lib/models/HookFilter.ts index b9b66fb8f3..03e8e6656d 100644 --- a/packages/nocodb/src/lib/models/HookFilter.ts +++ b/packages/nocodb/src/lib/models/HookFilter.ts @@ -205,10 +205,12 @@ export default class Filter { public async getChildren(ncMeta = Noco.ncMeta): Promise { if (this.children) return this.children; if (!this.is_group) return null; - let childFilters = await NocoCache.getList(CacheScope.FILTER_EXP, [ + const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [ this.id, ]); - if (!childFilters.length) { + let { list: childFilters } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !childFilters.length) { childFilters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_parent_id: this.id, @@ -243,8 +245,10 @@ export default class Filter { }, ncMeta = Noco.ncMeta ): Promise { - let filters = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); - if (!filters.length) { + const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); + let { list: filters } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !filters.length) { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_view_id: viewId }, }); @@ -327,8 +331,10 @@ export default class Filter { { viewId }: { viewId: any }, ncMeta = Noco.ncMeta ) { - let filterObjs = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); - if (!filterObjs.length) { + const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); + let { list: filterObjs } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !filterObjs.length) { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_view_id: viewId }, }); From 21be275f0cf5b3379369476f901498d8773bbf4b Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 10 Apr 2023 17:24:51 +0800 Subject: [PATCH 12/37] chore(nocodb): lint --- packages/nocodb/src/lib/models/FormViewColumn.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nocodb/src/lib/models/FormViewColumn.ts b/packages/nocodb/src/lib/models/FormViewColumn.ts index 790036fb06..4a67c6023b 100644 --- a/packages/nocodb/src/lib/models/FormViewColumn.ts +++ b/packages/nocodb/src/lib/models/FormViewColumn.ts @@ -102,7 +102,7 @@ export default class FormViewColumn implements FormColumnType { // if cache is not present skip pushing it into the list to avoid unexpected behaviour const { list } = await NocoCache.getList(CacheScope.FORM_VIEW_COLUMN, [ column.fk_view_id, - ]) + ]); if (list?.length) await NocoCache.appendToList( From e71230a0d47897f2c7452e6d1ec482e0d8d26d95 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 10:47:37 +0800 Subject: [PATCH 13/37] refactor(nocodb): adopt getList new format in View.ts --- packages/nocodb/src/lib/models/View.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/nocodb/src/lib/models/View.ts b/packages/nocodb/src/lib/models/View.ts index 2e7f9374f1..8e73878b21 100644 --- a/packages/nocodb/src/lib/models/View.ts +++ b/packages/nocodb/src/lib/models/View.ts @@ -205,8 +205,10 @@ export default class View implements ViewType { } public static async list(modelId: string, ncMeta = Noco.ncMeta) { - let viewsList = await NocoCache.getList(CacheScope.VIEW, [modelId]); - if (!viewsList.length) { + const cachedList = await NocoCache.getList(CacheScope.VIEW, [modelId]); + let { list: viewsList } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !viewsList.length) { viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { condition: { fk_model_id: modelId, @@ -1123,8 +1125,10 @@ export default class View implements ViewType { ); // get existing cache - const dataList = await NocoCache.getList(scope, [viewId]); - if (dataList?.length) { + const cachedList = await NocoCache.getList(scope, [viewId]); + let { list: dataList } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && dataList?.length) { for (const o of dataList) { if (!ignoreColdIds?.length || !ignoreColdIds.includes(o.fk_column_id)) { // set data @@ -1209,7 +1213,9 @@ export default class View implements ViewType { } // get existing cache - const dataList = await NocoCache.getList(scope, [viewId]); + const cachedList = await NocoCache.getList(scope, [viewId]); + let { list: dataList } = cachedList; + const { isEmptyList } = cachedList; const colsEssentialForView = view.type === ViewTypes.MAP @@ -1218,7 +1224,7 @@ export default class View implements ViewType { const mergedIgnoreColdIds = [...ignoreColdIds, ...colsEssentialForView]; - if (dataList?.length) { + if (!isEmptyList && dataList?.length) { for (const o of dataList) { if ( !mergedIgnoreColdIds?.length || @@ -1257,8 +1263,10 @@ export default class View implements ViewType { } static async shareViewList(tableId, ncMeta = Noco.ncMeta) { - let sharedViews = await NocoCache.getList(CacheScope.VIEW, [tableId]); - if (!sharedViews.length) { + let cachedList = await NocoCache.getList(CacheScope.VIEW, [tableId]); + let { list: sharedViews } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !sharedViews.length) { sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { xcCondition: { fk_model_id: { From a335da62486f90e01c299c512d2d382fc17866f1 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 10:47:41 +0800 Subject: [PATCH 14/37] refactor(nocodb): adopt getList new format in Sort.ts --- packages/nocodb/src/lib/models/Sort.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/models/Sort.ts b/packages/nocodb/src/lib/models/Sort.ts index 375fa3d09e..70d2cb6228 100644 --- a/packages/nocodb/src/lib/models/Sort.ts +++ b/packages/nocodb/src/lib/models/Sort.ts @@ -114,8 +114,10 @@ export default class Sort { ncMeta = Noco.ncMeta ): Promise { if (!viewId) return null; - let sortList = await NocoCache.getList(CacheScope.SORT, [viewId]); - if (!sortList.length) { + const cachedList = await NocoCache.getList(CacheScope.SORT, [viewId]); + let { list: sortList } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !sortList.length) { sortList = await ncMeta.metaList2(null, null, MetaTable.SORT, { condition: { fk_view_id: viewId }, orderBy: { From edbdbf704ed38fafdffd995b04aafd2705608eb3 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 10:47:49 +0800 Subject: [PATCH 15/37] refactor(nocodb): adopt getList new format in SelectOption.ts --- packages/nocodb/src/lib/models/SelectOption.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/models/SelectOption.ts b/packages/nocodb/src/lib/models/SelectOption.ts index 4575168375..fb868ef013 100644 --- a/packages/nocodb/src/lib/models/SelectOption.ts +++ b/packages/nocodb/src/lib/models/SelectOption.ts @@ -69,10 +69,12 @@ export default class SelectOption implements SelectOptionType { } public static async read(fk_column_id: string, ncMeta = Noco.ncMeta) { - let options = await NocoCache.getList(CacheScope.COL_SELECT_OPTION, [ + const cachedList = await NocoCache.getList(CacheScope.COL_SELECT_OPTION, [ fk_column_id, ]); - if (!options.length) { + let { list: options } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !options.length) { options = await ncMeta.metaList2( null, //, null, //model.db_alias, From 232b58e797e74d87d7535dfb09cfb63dc88e3ce8 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 10:47:54 +0800 Subject: [PATCH 16/37] refactor(nocodb): adopt getList new format in ProjectUser.ts --- packages/nocodb/src/lib/models/ProjectUser.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/models/ProjectUser.ts b/packages/nocodb/src/lib/models/ProjectUser.ts index 1090a10c2e..12180cdd06 100644 --- a/packages/nocodb/src/lib/models/ProjectUser.ts +++ b/packages/nocodb/src/lib/models/ProjectUser.ts @@ -187,10 +187,12 @@ export default class ProjectUser { } // remove project from user project list cache - let cachedProjectList = await NocoCache.getList(CacheScope.USER_PROJECT, [ + const cachedList = await NocoCache.getList(CacheScope.USER_PROJECT, [ userId, ]); - if (cachedProjectList?.length) { + let { list: cachedProjectList } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && cachedProjectList?.length) { cachedProjectList = cachedProjectList.filter((p) => p.id !== projectId); await NocoCache.setList( CacheScope.USER_PROJECT, From 0cb5f2f369dbed000dbf4865a3fd15214ecdb9b1 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 10:48:00 +0800 Subject: [PATCH 17/37] refactor(nocodb): adopt getList new format in Project.ts --- packages/nocodb/src/lib/models/Project.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/models/Project.ts b/packages/nocodb/src/lib/models/Project.ts index a26ac98a08..2fefddd3e1 100644 --- a/packages/nocodb/src/lib/models/Project.ts +++ b/packages/nocodb/src/lib/models/Project.ts @@ -79,8 +79,10 @@ export default class Project implements ProjectType { ncMeta = Noco.ncMeta ): Promise { // todo: pagination - let projectList = await NocoCache.getList(CacheScope.PROJECT, []); - if (!projectList.length) { + const cachedList = await NocoCache.getList(CacheScope.PROJECT, []); + let { list: projectList } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !projectList.length) { projectList = await ncMeta.metaList2(null, null, MetaTable.PROJECT, { xcCondition: { _or: [ From 472f02ba15a0eea84a5800fd414e2cadfe7c766e Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 10:48:07 +0800 Subject: [PATCH 18/37] refactor(nocodb): adopt getList new format in Plugin.ts --- packages/nocodb/src/lib/models/Plugin.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/models/Plugin.ts b/packages/nocodb/src/lib/models/Plugin.ts index 5d88dc529e..46b322ac5a 100644 --- a/packages/nocodb/src/lib/models/Plugin.ts +++ b/packages/nocodb/src/lib/models/Plugin.ts @@ -43,8 +43,10 @@ export default class Plugin implements PluginType { } static async list(ncMeta = Noco.ncMeta) { - let pluginList = await NocoCache.getList(CacheScope.PLUGIN, []); - if (!pluginList.length) { + const cachedList = await NocoCache.getList(CacheScope.PLUGIN, []); + let { list: pluginList } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !pluginList.length) { pluginList = await ncMeta.metaList2(null, null, MetaTable.PLUGIN); await NocoCache.setList(CacheScope.PLUGIN, [], pluginList); } From 7cebf09099b810444bb73e22fef249ab425fb3ef Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 10:48:16 +0800 Subject: [PATCH 19/37] refactor(nocodb): adopt getList new format in ModelRoleVisibility.ts --- packages/nocodb/src/lib/models/ModelRoleVisibility.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/models/ModelRoleVisibility.ts b/packages/nocodb/src/lib/models/ModelRoleVisibility.ts index 7813a94171..f30419619e 100644 --- a/packages/nocodb/src/lib/models/ModelRoleVisibility.ts +++ b/packages/nocodb/src/lib/models/ModelRoleVisibility.ts @@ -24,10 +24,12 @@ export default class ModelRoleVisibility implements ModelRoleVisibilityType { } static async list(projectId): Promise { - let data = await NocoCache.getList(CacheScope.MODEL_ROLE_VISIBILITY, [ + const cachedList = await NocoCache.getList(CacheScope.MODEL_ROLE_VISIBILITY, [ projectId, ]); - if (!data.length) { + let { list: data } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !data.length) { data = await Noco.ncMeta.metaList2( projectId, null, From ae34cb67e074d30181e0f673c51a9535bcc4350a Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 10:48:22 +0800 Subject: [PATCH 20/37] refactor(nocodb): adopt getList new format in Model.ts --- packages/nocodb/src/lib/models/Model.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/lib/models/Model.ts b/packages/nocodb/src/lib/models/Model.ts index 1128aceb73..fbba8090e4 100644 --- a/packages/nocodb/src/lib/models/Model.ts +++ b/packages/nocodb/src/lib/models/Model.ts @@ -160,13 +160,15 @@ export default class Model implements TableType { }, ncMeta = Noco.ncMeta ): Promise { - let modelList = []; + let cachedList; if (base_id) { - await NocoCache.getList(CacheScope.MODEL, [project_id, base_id]); + cachedList = await NocoCache.getList(CacheScope.MODEL, [project_id, base_id]); } else { - await NocoCache.getList(CacheScope.MODEL, [project_id]); + cachedList = await NocoCache.getList(CacheScope.MODEL, [project_id]); } - if (!modelList.length) { + let { list: modelList } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !modelList.length) { modelList = await ncMeta.metaList2( project_id, base_id, From 224c5a37bdd669cff39d0bf79c14513973219ace Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 10:48:29 +0800 Subject: [PATCH 21/37] refactor(nocodb): adopt getList new format in MapViewColumn.ts --- packages/nocodb/src/lib/models/MapViewColumn.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/lib/models/MapViewColumn.ts b/packages/nocodb/src/lib/models/MapViewColumn.ts index a5781bf1df..4c4ad4e0f2 100644 --- a/packages/nocodb/src/lib/models/MapViewColumn.ts +++ b/packages/nocodb/src/lib/models/MapViewColumn.ts @@ -67,10 +67,8 @@ export default class MapViewColumn { await NocoCache.set(`${CacheScope.MAP_VIEW_COLUMN}:${fk_column_id}`, id); // if cache is not present skip pushing it into the list to avoid unexpected behaviour - if ( - (await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [column.fk_view_id])) - ?.length - ) + const { list } = await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [column.fk_view_id]); + if (list?.length) await NocoCache.appendToList( CacheScope.MAP_VIEW_COLUMN, [column.fk_view_id], From 81c4d6bf925a270436964351647ccadc81783358 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 10:48:37 +0800 Subject: [PATCH 22/37] refactor(nocodb): adopt getList new format in KanbanViewColumn.ts --- packages/nocodb/src/lib/models/KanbanViewColumn.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/models/KanbanViewColumn.ts b/packages/nocodb/src/lib/models/KanbanViewColumn.ts index 71e58954dd..8ebeb28298 100644 --- a/packages/nocodb/src/lib/models/KanbanViewColumn.ts +++ b/packages/nocodb/src/lib/models/KanbanViewColumn.ts @@ -85,10 +85,12 @@ export default class KanbanViewColumn implements KanbanColumnType { viewId: string, ncMeta = Noco.ncMeta ): Promise { - let views = await NocoCache.getList(CacheScope.KANBAN_VIEW_COLUMN, [ + const cachedList = await NocoCache.getList(CacheScope.KANBAN_VIEW_COLUMN, [ viewId, ]); - if (!views.length) { + let { list: views } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !views.length) { views = await ncMeta.metaList2( null, null, From ad8f5cfef204b02d01bbe146bc7bf83b5e80c72c Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 10:56:35 +0800 Subject: [PATCH 23/37] refactor(nocodb): adopt getList new format in Model.ts --- packages/nocodb/src/lib/models/Model.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/nocodb/src/lib/models/Model.ts b/packages/nocodb/src/lib/models/Model.ts index fbba8090e4..aa1b4486ae 100644 --- a/packages/nocodb/src/lib/models/Model.ts +++ b/packages/nocodb/src/lib/models/Model.ts @@ -162,7 +162,10 @@ export default class Model implements TableType { ): Promise { let cachedList; if (base_id) { - cachedList = await NocoCache.getList(CacheScope.MODEL, [project_id, base_id]); + cachedList = await NocoCache.getList(CacheScope.MODEL, [ + project_id, + base_id, + ]); } else { cachedList = await NocoCache.getList(CacheScope.MODEL, [project_id]); } @@ -213,11 +216,13 @@ export default class Model implements TableType { }, ncMeta = Noco.ncMeta ): Promise { - let modelList = await NocoCache.getList(CacheScope.MODEL, [ + const cachedList = await NocoCache.getList(CacheScope.MODEL, [ project_id, db_alias, ]); - if (!modelList.length) { + let { list: modelList } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !modelList.length) { modelList = await ncMeta.metaList2( project_id, db_alias, From 5dc9e469ccdfd2cb757635c00de72930103db217 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 11:31:12 +0800 Subject: [PATCH 24/37] refactor(nocodb): adopt getList new format in GalleryViewColumn.ts --- packages/nocodb/src/lib/models/GalleryViewColumn.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/models/GalleryViewColumn.ts b/packages/nocodb/src/lib/models/GalleryViewColumn.ts index 8ddf12b6e1..1837c334f2 100644 --- a/packages/nocodb/src/lib/models/GalleryViewColumn.ts +++ b/packages/nocodb/src/lib/models/GalleryViewColumn.ts @@ -97,10 +97,12 @@ export default class GalleryViewColumn { viewId: string, ncMeta = Noco.ncMeta ): Promise { - let views = await NocoCache.getList(CacheScope.GALLERY_VIEW_COLUMN, [ + const cachedList = await NocoCache.getList(CacheScope.GALLERY_VIEW_COLUMN, [ viewId, ]); - if (!views.length) { + let { list: views } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !views.length) { views = await ncMeta.metaList2( null, null, From 157162823d308cb13874e4a514e5d5b704210576 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 11:33:13 +0800 Subject: [PATCH 25/37] refactor(nocodb): adopt getList new format in ProjectUser.ts --- packages/nocodb/src/lib/models/ProjectUser.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/models/ProjectUser.ts b/packages/nocodb/src/lib/models/ProjectUser.ts index 12180cdd06..da45f180e8 100644 --- a/packages/nocodb/src/lib/models/ProjectUser.ts +++ b/packages/nocodb/src/lib/models/ProjectUser.ts @@ -223,11 +223,13 @@ export default class ProjectUser { ncMeta = Noco.ncMeta ): Promise { // todo: pagination - let projectList = await NocoCache.getList(CacheScope.USER_PROJECT, [ + const cachedList = await NocoCache.getList(CacheScope.USER_PROJECT, [ userId, ]); + let { list: projectList } = cachedList; + const { isEmptyList } = cachedList; - if (projectList.length) { + if (!isEmptyList && projectList.length) { return projectList; } From 1697c75f41bb2093c56b6b1fce6cfd5f2729d7f3 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 11:33:27 +0800 Subject: [PATCH 26/37] refactor(nocodb): adopt getList new format in MapViewColumn.ts --- packages/nocodb/src/lib/models/MapViewColumn.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/nocodb/src/lib/models/MapViewColumn.ts b/packages/nocodb/src/lib/models/MapViewColumn.ts index 4c4ad4e0f2..a14d901892 100644 --- a/packages/nocodb/src/lib/models/MapViewColumn.ts +++ b/packages/nocodb/src/lib/models/MapViewColumn.ts @@ -67,7 +67,9 @@ export default class MapViewColumn { await NocoCache.set(`${CacheScope.MAP_VIEW_COLUMN}:${fk_column_id}`, id); // if cache is not present skip pushing it into the list to avoid unexpected behaviour - const { list } = await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [column.fk_view_id]); + const { list } = await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [ + column.fk_view_id, + ]); if (list?.length) await NocoCache.appendToList( CacheScope.MAP_VIEW_COLUMN, @@ -82,8 +84,12 @@ export default class MapViewColumn { viewId: string, ncMeta = Noco.ncMeta ): Promise { - let views = await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [viewId]); - if (!views.length) { + const cachedList = await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [ + viewId, + ]); + let { list: views } = cachedList; + const { isEmptyList } = cachedList; + if (!isEmptyList && !views.length) { views = await ncMeta.metaList2(null, null, MetaTable.MAP_VIEW_COLUMNS, { condition: { fk_view_id: viewId, From c1ee8d9dd2bdc5abf2b2e223a21456a00e155b64 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 11:33:59 +0800 Subject: [PATCH 27/37] refactor(nocodb): lint --- packages/nocodb/src/lib/models/ModelRoleVisibility.ts | 7 ++++--- packages/nocodb/src/lib/models/View.ts | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/nocodb/src/lib/models/ModelRoleVisibility.ts b/packages/nocodb/src/lib/models/ModelRoleVisibility.ts index f30419619e..03ef7d55da 100644 --- a/packages/nocodb/src/lib/models/ModelRoleVisibility.ts +++ b/packages/nocodb/src/lib/models/ModelRoleVisibility.ts @@ -24,9 +24,10 @@ export default class ModelRoleVisibility implements ModelRoleVisibilityType { } static async list(projectId): Promise { - const cachedList = await NocoCache.getList(CacheScope.MODEL_ROLE_VISIBILITY, [ - projectId, - ]); + const cachedList = await NocoCache.getList( + CacheScope.MODEL_ROLE_VISIBILITY, + [projectId] + ); let { list: data } = cachedList; const { isEmptyList } = cachedList; if (!isEmptyList && !data.length) { diff --git a/packages/nocodb/src/lib/models/View.ts b/packages/nocodb/src/lib/models/View.ts index 8e73878b21..e9f89b37e4 100644 --- a/packages/nocodb/src/lib/models/View.ts +++ b/packages/nocodb/src/lib/models/View.ts @@ -1126,7 +1126,7 @@ export default class View implements ViewType { // get existing cache const cachedList = await NocoCache.getList(scope, [viewId]); - let { list: dataList } = cachedList; + const { list: dataList } = cachedList; const { isEmptyList } = cachedList; if (!isEmptyList && dataList?.length) { for (const o of dataList) { @@ -1214,7 +1214,7 @@ export default class View implements ViewType { // get existing cache const cachedList = await NocoCache.getList(scope, [viewId]); - let { list: dataList } = cachedList; + const { list: dataList } = cachedList; const { isEmptyList } = cachedList; const colsEssentialForView = @@ -1263,7 +1263,7 @@ export default class View implements ViewType { } static async shareViewList(tableId, ncMeta = Noco.ncMeta) { - let cachedList = await NocoCache.getList(CacheScope.VIEW, [tableId]); + const cachedList = await NocoCache.getList(CacheScope.VIEW, [tableId]); let { list: sharedViews } = cachedList; const { isEmptyList } = cachedList; if (!isEmptyList && !sharedViews.length) { From d685c5aff448d81924d994905b23abacbc9d3531 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 11:44:22 +0800 Subject: [PATCH 28/37] fix(nocodb): set isEmptyList for false --- packages/nocodb/src/lib/cache/NocoCache.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nocodb/src/lib/cache/NocoCache.ts b/packages/nocodb/src/lib/cache/NocoCache.ts index f00183edc1..d50bdabc6b 100644 --- a/packages/nocodb/src/lib/cache/NocoCache.ts +++ b/packages/nocodb/src/lib/cache/NocoCache.ts @@ -63,7 +63,7 @@ export default class NocoCache { if (this.cacheDisabled) return Promise.resolve({ list: [], - isEmptyList: true, + isEmptyList: false, }); return this.client.getList(scope, subKeys); } From b424f22dda98d9a9605d490caeb2666ca097e140 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 14:03:39 +0800 Subject: [PATCH 29/37] fix(nocodb): only set none list for FILTER_EXP, SORT, and MODEL_ROLE_VISIBILITY --- packages/nocodb/src/lib/cache/RedisCacheMgr.ts | 11 ++++++++++- packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts index b8a457c3c9..81c12be319 100644 --- a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts @@ -158,7 +158,16 @@ export default class RedisCacheMgr extends CacheMgr { ? `${this.prefix}:${scope}:list` : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; if (!list.length) { - return this.set(listKey, ['NONE']); + if ( + [ + CacheScope.FILTER_EXP, + CacheScope.SORT, + CacheScope.MODEL_ROLE_VISIBILITY, + ].includes(scope as CacheScope) + ) { + return this.set(listKey, ['NONE']); + } + return Promise.resolve(true); } // fetch existing list const listOfGetKeys = diff --git a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts index 53d084abab..a2fe30c10b 100644 --- a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts @@ -158,7 +158,16 @@ export default class RedisMockCacheMgr extends CacheMgr { ? `${this.prefix}:${scope}:list` : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; if (!list.length) { - return this.set(listKey, ['NONE']); + if ( + [ + CacheScope.FILTER_EXP, + CacheScope.SORT, + CacheScope.MODEL_ROLE_VISIBILITY, + ].includes(scope as CacheScope) + ) { + return this.set(listKey, ['NONE']); + } + return Promise.resolve(true); } // fetch existing list const listOfGetKeys = From d2cfe2e36678075aa84a9c8a9132349398c6a48a Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 14:46:52 +0800 Subject: [PATCH 30/37] fix(nocodb): handle NONE in appendToList --- packages/nocodb/src/lib/cache/RedisCacheMgr.ts | 6 +++++- packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts index 81c12be319..1f4b0170e6 100644 --- a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts @@ -247,7 +247,11 @@ export default class RedisCacheMgr extends CacheMgr { ? `${this.prefix}:${scope}:list` : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; log(`RedisCacheMgr::appendToList: append key ${key} to ${listKey}`); - const list = (await this.get(listKey, CacheGetType.TYPE_ARRAY)) || []; + let list = (await this.get(listKey, CacheGetType.TYPE_ARRAY)) || []; + if (list.length === 1 && list[0] === 'NONE') { + list = []; + await this.del(listKey); + } list.push(key); return this.set(listKey, list); } diff --git a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts index a2fe30c10b..0d83ba5b1b 100644 --- a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts @@ -247,7 +247,11 @@ export default class RedisMockCacheMgr extends CacheMgr { ? `${this.prefix}:${scope}:list` : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; log(`RedisMockCacheMgr::appendToList: append key ${key} to ${listKey}`); - const list = (await this.get(listKey, CacheGetType.TYPE_ARRAY)) || []; + let list = (await this.get(listKey, CacheGetType.TYPE_ARRAY)) || []; + if (list.length === 1 && list[0] === 'NONE') { + list = []; + await this.del(listKey); + } list.push(key); return this.set(listKey, list); } From 67bd3f739792f96ef5236a0ffc4a7f41ac66b861 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 21:25:42 +0800 Subject: [PATCH 31/37] 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: { From b7387731acbffce9893dbf8e8a10e6439d474e57 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 21:46:47 +0800 Subject: [PATCH 32/37] refactor(nocodb): lint --- packages/nocodb/src/lib/models/Model.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/nocodb/src/lib/models/Model.ts b/packages/nocodb/src/lib/models/Model.ts index e620f34987..54d621aee5 100644 --- a/packages/nocodb/src/lib/models/Model.ts +++ b/packages/nocodb/src/lib/models/Model.ts @@ -160,9 +160,7 @@ export default class Model implements TableType { }, ncMeta = Noco.ncMeta ): Promise { - const cachedList = await NocoCache.getList(CacheScope.MODEL, [ - project_id, - ]); + const cachedList = await NocoCache.getList(CacheScope.MODEL, [project_id]); let { list: modelList } = cachedList; if (!modelList.length) { From 3df9b42a9a3cc75e89d81b6dedd8a940dd432b80 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 11 Apr 2023 21:47:00 +0800 Subject: [PATCH 33/37] fix(nocodb): cache logic --- .../nocodb/src/lib/cache/RedisCacheMgr.ts | 23 ++++++++------ .../nocodb/src/lib/cache/RedisMockCacheMgr.ts | 30 +++++++++++-------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts index 1f4b0170e6..7ce7427f5e 100644 --- a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts @@ -44,7 +44,7 @@ export default class RedisCacheMgr extends CacheMgr { async get(key: string, type: string, config?: any): Promise { log(`RedisCacheMgr::get: getting key ${key} with type ${type}`); if (type === CacheGetType.TYPE_ARRAY) { - return await this.client.smembers(key); + return this.client.smembers(key); } else if (type === CacheGetType.TYPE_OBJECT) { const res = await this.client.get(key); try { @@ -131,15 +131,20 @@ export default class RedisCacheMgr extends CacheMgr { // e.g. arr = ["nc:::", "nc:::"] const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; log(`RedisCacheMgr::getList: getting list with key ${key}`); - let list: any[] = []; - const isEmptyList = arr[0] === 'NONE'; - if (!isEmptyList) { - list = await Promise.all( - arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) - ); + + const isEmptyList = arr.length && arr[0] === 'NONE'; + + if (isEmptyList) { + return Promise.resolve({ + list: [], + isEmptyList, + }); } + return { - list, + list: await Promise.all( + arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) + ), isEmptyList, }; } @@ -248,7 +253,7 @@ export default class RedisCacheMgr extends CacheMgr { : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; log(`RedisCacheMgr::appendToList: append key ${key} to ${listKey}`); let list = (await this.get(listKey, CacheGetType.TYPE_ARRAY)) || []; - if (list.length === 1 && list[0] === 'NONE') { + if (list.length && list[0] === 'NONE') { list = []; await this.del(listKey); } diff --git a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts index 0d83ba5b1b..34fb5962a6 100644 --- a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts @@ -2,6 +2,7 @@ import debug from 'debug'; import Redis from 'ioredis-mock'; import { CacheDelDirection, CacheGetType, CacheScope } from '../utils/globals'; import CacheMgr from './CacheMgr'; + const log = debug('nc:cache'); export default class RedisMockCacheMgr extends CacheMgr { @@ -43,7 +44,7 @@ export default class RedisMockCacheMgr extends CacheMgr { async get(key: string, type: string, config?: any): Promise { log(`RedisMockCacheMgr::get: getting key ${key} with type ${type}`); if (type === CacheGetType.TYPE_ARRAY) { - return await this.client.smembers(key); + return this.client.smembers(key); } else if (type === CacheGetType.TYPE_OBJECT) { const res = await this.client.get(key); try { @@ -102,10 +103,9 @@ export default class RedisMockCacheMgr extends CacheMgr { `RedisMockCacheMgr::delAll: deleting all keys with pattern ${this.prefix}:${scope}:${pattern}` ); await Promise.all( - keys.map( - async (k) => - await this.deepDel(scope, k, CacheDelDirection.CHILD_TO_PARENT) - ) + keys.map(async (k) => { + await this.deepDel(scope, k, CacheDelDirection.CHILD_TO_PARENT); + }) ); return Promise.all( keys.map(async (k) => { @@ -131,15 +131,19 @@ export default class RedisMockCacheMgr extends CacheMgr { // e.g. arr = ["nc:::", "nc:::"] const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; log(`RedisMockCacheMgr::getList: getting list with key ${key}`); - let list: any[] = []; - const isEmptyList = arr[0] === 'NONE'; - if (!isEmptyList) { - list = await Promise.all( - arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) - ); + const isEmptyList = arr.length && arr[0] === 'NONE'; + + if (isEmptyList) { + return Promise.resolve({ + list: [], + isEmptyList, + }); } + return { - list, + list: await Promise.all( + arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) + ), isEmptyList, }; } @@ -248,7 +252,7 @@ export default class RedisMockCacheMgr extends CacheMgr { : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; log(`RedisMockCacheMgr::appendToList: append key ${key} to ${listKey}`); let list = (await this.get(listKey, CacheGetType.TYPE_ARRAY)) || []; - if (list.length === 1 && list[0] === 'NONE') { + if (list.length && list[0] === 'NONE') { list = []; await this.del(listKey); } From a4be82b3915b2cea400d7dad52d5ebd1bb814da7 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 12 Apr 2023 12:04:30 +0800 Subject: [PATCH 34/37] refactor(nocodb): rename to isNoneList --- packages/nocodb/src/lib/cache/CacheMgr.ts | 2 +- packages/nocodb/src/lib/cache/NocoCache.ts | 4 ++-- .../nocodb/src/lib/cache/RedisCacheMgr.ts | 12 ++++++---- .../nocodb/src/lib/cache/RedisMockCacheMgr.ts | 10 ++++---- packages/nocodb/src/lib/models/Column.ts | 8 +++---- packages/nocodb/src/lib/models/Filter.ts | 24 +++++++++---------- .../src/lib/models/ModelRoleVisibility.ts | 4 ++-- packages/nocodb/src/lib/models/Sort.ts | 4 ++-- 8 files changed, 35 insertions(+), 33 deletions(-) diff --git a/packages/nocodb/src/lib/cache/CacheMgr.ts b/packages/nocodb/src/lib/cache/CacheMgr.ts index 4554072a7a..4a2303c4b9 100644 --- a/packages/nocodb/src/lib/cache/CacheMgr.ts +++ b/packages/nocodb/src/lib/cache/CacheMgr.ts @@ -9,7 +9,7 @@ export default abstract class CacheMgr { list: string[] ): Promise<{ list: any[]; - isEmptyList: boolean; + isNoneList: boolean; }>; public abstract setList( scope: string, diff --git a/packages/nocodb/src/lib/cache/NocoCache.ts b/packages/nocodb/src/lib/cache/NocoCache.ts index d50bdabc6b..25fed59ea3 100644 --- a/packages/nocodb/src/lib/cache/NocoCache.ts +++ b/packages/nocodb/src/lib/cache/NocoCache.ts @@ -58,12 +58,12 @@ export default class NocoCache { subKeys: string[] ): Promise<{ list: any[]; - isEmptyList: boolean; + isNoneList: boolean; }> { if (this.cacheDisabled) return Promise.resolve({ list: [], - isEmptyList: false, + isNoneList: false, }); return this.client.getList(scope, subKeys); } diff --git a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts index 7ce7427f5e..25c8022fb3 100644 --- a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts @@ -119,7 +119,7 @@ export default class RedisCacheMgr extends CacheMgr { subKeys: string[] ): Promise<{ list: any[]; - isEmptyList: boolean; + isNoneList: boolean; }> { // remove null from arrays subKeys = subKeys.filter((k) => k); @@ -132,12 +132,12 @@ export default class RedisCacheMgr extends CacheMgr { const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; log(`RedisCacheMgr::getList: getting list with key ${key}`); - const isEmptyList = arr.length && arr[0] === 'NONE'; + const isNoneList = arr.length && arr[0] === 'NONE'; - if (isEmptyList) { + if (isNoneList) { return Promise.resolve({ list: [], - isEmptyList, + isNoneList, }); } @@ -145,7 +145,7 @@ export default class RedisCacheMgr extends CacheMgr { list: await Promise.all( arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) ), - isEmptyList, + isNoneList, }; } @@ -170,8 +170,10 @@ export default class RedisCacheMgr extends CacheMgr { CacheScope.MODEL_ROLE_VISIBILITY, ].includes(scope as CacheScope) ) { + // Set NONE here so that it won't hit the DB on each page load return this.set(listKey, ['NONE']); } + console.log('HERE'); return Promise.resolve(true); } // fetch existing list diff --git a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts index 34fb5962a6..0f82bd4185 100644 --- a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts @@ -119,7 +119,7 @@ export default class RedisMockCacheMgr extends CacheMgr { subKeys: string[] ): Promise<{ list: any[]; - isEmptyList: boolean; + isNoneList: boolean; }> { // remove null from arrays subKeys = subKeys.filter((k) => k); @@ -131,12 +131,12 @@ export default class RedisMockCacheMgr extends CacheMgr { // e.g. arr = ["nc:::", "nc:::"] const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; log(`RedisMockCacheMgr::getList: getting list with key ${key}`); - const isEmptyList = arr.length && arr[0] === 'NONE'; + const isNoneList = arr.length && arr[0] === 'NONE'; - if (isEmptyList) { + if (isNoneList) { return Promise.resolve({ list: [], - isEmptyList, + isNoneList, }); } @@ -144,7 +144,7 @@ export default class RedisMockCacheMgr extends CacheMgr { list: await Promise.all( arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) ), - isEmptyList, + isNoneList, }; } diff --git a/packages/nocodb/src/lib/models/Column.ts b/packages/nocodb/src/lib/models/Column.ts index 85610bd32c..ac3c5ade96 100644 --- a/packages/nocodb/src/lib/models/Column.ts +++ b/packages/nocodb/src/lib/models/Column.ts @@ -721,8 +721,8 @@ export default class Column implements ColumnType { { const cachedList = await NocoCache.getList(CacheScope.SORT, [id]); let { list: sorts } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !sorts.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !sorts.length) { sorts = await ncMeta.metaList2(null, null, MetaTable.SORT, { condition: { fk_column_id: id, @@ -737,8 +737,8 @@ export default class Column implements ColumnType { { const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [id]); let { list: filters } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !filters.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !filters.length) { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_column_id: id, diff --git a/packages/nocodb/src/lib/models/Filter.ts b/packages/nocodb/src/lib/models/Filter.ts index aa6afd20c0..54d5d3c4e6 100644 --- a/packages/nocodb/src/lib/models/Filter.ts +++ b/packages/nocodb/src/lib/models/Filter.ts @@ -330,8 +330,8 @@ export default class Filter implements FilterType { this.id, ]); let { list: childFilters } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !childFilters.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !childFilters.length) { childFilters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_parent_id: this.id, @@ -375,8 +375,8 @@ export default class Filter implements FilterType { viewId || hookId, ]); let { list: filters } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !filters.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !filters.length) { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: viewId ? { fk_view_id: viewId } : { fk_hook_id: hookId }, orderBy: { @@ -486,8 +486,8 @@ export default class Filter implements FilterType { ) { const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); let { list: filterObjs } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !filterObjs.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !filterObjs.length) { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_view_id: viewId }, orderBy: { @@ -507,8 +507,8 @@ export default class Filter implements FilterType { ) { const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [hookId]); let { list: filterObjs } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !filterObjs.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !filterObjs.length) { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_hook_id: hookId }, orderBy: { @@ -532,8 +532,8 @@ export default class Filter implements FilterType { parentId, ]); let { list: filterObjs } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !filterObjs.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !filterObjs.length) { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_parent_id: parentId, @@ -563,8 +563,8 @@ export default class Filter implements FilterType { parentId, ]); let { list: filterObjs } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !filterObjs.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !filterObjs.length) { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_parent_id: parentId, diff --git a/packages/nocodb/src/lib/models/ModelRoleVisibility.ts b/packages/nocodb/src/lib/models/ModelRoleVisibility.ts index 03ef7d55da..724ecaf07b 100644 --- a/packages/nocodb/src/lib/models/ModelRoleVisibility.ts +++ b/packages/nocodb/src/lib/models/ModelRoleVisibility.ts @@ -29,8 +29,8 @@ export default class ModelRoleVisibility implements ModelRoleVisibilityType { [projectId] ); let { list: data } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !data.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !data.length) { data = await Noco.ncMeta.metaList2( projectId, null, diff --git a/packages/nocodb/src/lib/models/Sort.ts b/packages/nocodb/src/lib/models/Sort.ts index 70d2cb6228..7a020cde03 100644 --- a/packages/nocodb/src/lib/models/Sort.ts +++ b/packages/nocodb/src/lib/models/Sort.ts @@ -116,8 +116,8 @@ export default class Sort { if (!viewId) return null; const cachedList = await NocoCache.getList(CacheScope.SORT, [viewId]); let { list: sortList } = cachedList; - const { isEmptyList } = cachedList; - if (!isEmptyList && !sortList.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !sortList.length) { sortList = await ncMeta.metaList2(null, null, MetaTable.SORT, { condition: { fk_view_id: viewId }, orderBy: { From e8dda4426d6183de5bd49682c9a70b824f7dc43a Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 12 Apr 2023 13:32:16 +0800 Subject: [PATCH 35/37] feat(nocodb): add isNoneList --- packages/nocodb/src/lib/models/Base.ts | 3 ++- packages/nocodb/src/lib/models/Column.ts | 18 ++++++++++++------ .../nocodb/src/lib/models/FormViewColumn.ts | 3 ++- .../nocodb/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 | 7 ++++--- packages/nocodb/src/lib/models/Plugin.ts | 3 ++- packages/nocodb/src/lib/models/Project.ts | 3 ++- packages/nocodb/src/lib/models/ProjectUser.ts | 6 ++++-- packages/nocodb/src/lib/models/SelectOption.ts | 3 ++- packages/nocodb/src/lib/models/View.ts | 12 ++++++++---- 15 files changed, 54 insertions(+), 28 deletions(-) diff --git a/packages/nocodb/src/lib/models/Base.ts b/packages/nocodb/src/lib/models/Base.ts index 3df992a791..bfd29c18fb 100644 --- a/packages/nocodb/src/lib/models/Base.ts +++ b/packages/nocodb/src/lib/models/Base.ts @@ -154,7 +154,8 @@ export default class Base implements BaseType { args.projectId, ]); let { list: baseDataList } = cachedList; - if (!baseDataList.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 ac3c5ade96..51b4e60d47 100644 --- a/packages/nocodb/src/lib/models/Column.ts +++ b/packages/nocodb/src/lib/models/Column.ts @@ -478,7 +478,8 @@ export default class Column implements ColumnType { fk_model_id, ]); let { list: columnsList } = cachedList; - if (!columnsList.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !columnsList.length) { columnsList = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, { condition: { fk_model_id, @@ -632,7 +633,8 @@ export default class Column implements ColumnType { { const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); let { list: lookups } = cachedList; - if (!lookups.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !lookups.length) { lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { condition: { fk_lookup_column_id: id }, }); @@ -646,7 +648,8 @@ export default class Column implements ColumnType { { const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]); let { list: rollups } = cachedList; - if (!rollups.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !rollups.length) { rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, { condition: { fk_rollup_column_id: id }, }); @@ -661,7 +664,8 @@ export default class Column implements ColumnType { col.fk_model_id, ]); let { list: formulaColumns } = cachedList; - if (!formulaColumns.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !formulaColumns.length) { formulaColumns = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, { condition: { fk_model_id: col.fk_model_id, @@ -692,7 +696,8 @@ 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; - if (!lookups.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !lookups.length) { lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { condition: { fk_relation_column_id: id }, }); @@ -706,7 +711,8 @@ 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; - if (!rollups.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 0255aa3db5..06ff209fda 100644 --- a/packages/nocodb/src/lib/models/FormViewColumn.ts +++ b/packages/nocodb/src/lib/models/FormViewColumn.ts @@ -121,7 +121,8 @@ export default class FormViewColumn implements FormColumnType { viewId, ]); let { list: viewColumns } = cachedList; - if (!viewColumns.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 d354f61606..d20bb881e5 100644 --- a/packages/nocodb/src/lib/models/GalleryViewColumn.ts +++ b/packages/nocodb/src/lib/models/GalleryViewColumn.ts @@ -101,7 +101,8 @@ export default class GalleryViewColumn { viewId, ]); let { list: views } = cachedList; - if (!views.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 1c5e3e1258..8bd0497f56 100644 --- a/packages/nocodb/src/lib/models/GridViewColumn.ts +++ b/packages/nocodb/src/lib/models/GridViewColumn.ts @@ -28,7 +28,8 @@ export default class GridViewColumn implements GridColumnType { viewId, ]); let { list: views } = cachedList; - if (!views.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 f01044fdcb..aeef9e96a0 100644 --- a/packages/nocodb/src/lib/models/Hook.ts +++ b/packages/nocodb/src/lib/models/Hook.ts @@ -89,7 +89,8 @@ export default class Hook implements HookType { param.fk_model_id, ]); let { list: hooks } = cachedList; - if (!hooks.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 2a1610b3e8..4f3bdb2488 100644 --- a/packages/nocodb/src/lib/models/HookFilter.ts +++ b/packages/nocodb/src/lib/models/HookFilter.ts @@ -209,7 +209,8 @@ export default class Filter { this.id, ]); let { list: childFilters } = cachedList; - if (!childFilters.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !childFilters.length) { childFilters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_parent_id: this.id, @@ -246,7 +247,8 @@ export default class Filter { ): Promise { const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); let { list: filters } = cachedList; - if (!filters.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !filters.length) { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { condition: { fk_view_id: viewId }, }); @@ -331,7 +333,8 @@ export default class Filter { ) { const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); let { list: filterObjs } = cachedList; - if (!filterObjs.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 e64b030991..cea673e14d 100644 --- a/packages/nocodb/src/lib/models/KanbanViewColumn.ts +++ b/packages/nocodb/src/lib/models/KanbanViewColumn.ts @@ -89,7 +89,8 @@ export default class KanbanViewColumn implements KanbanColumnType { viewId, ]); let { list: views } = cachedList; - if (!views.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 42958825c6..3d38af9e5d 100644 --- a/packages/nocodb/src/lib/models/MapViewColumn.ts +++ b/packages/nocodb/src/lib/models/MapViewColumn.ts @@ -88,7 +88,8 @@ export default class MapViewColumn { viewId, ]); let { list: views } = cachedList; - if (!views.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 54d621aee5..abfea84ef9 100644 --- a/packages/nocodb/src/lib/models/Model.ts +++ b/packages/nocodb/src/lib/models/Model.ts @@ -162,8 +162,8 @@ export default class Model implements TableType { ): Promise { const cachedList = await NocoCache.getList(CacheScope.MODEL, [project_id]); let { list: modelList } = cachedList; - - if (!modelList.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !modelList.length) { modelList = await ncMeta.metaList2( project_id, base_id, @@ -205,7 +205,8 @@ export default class Model implements TableType { db_alias, ]); let { list: modelList } = cachedList; - if (!modelList.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 e58f640385..1740853253 100644 --- a/packages/nocodb/src/lib/models/Plugin.ts +++ b/packages/nocodb/src/lib/models/Plugin.ts @@ -45,7 +45,8 @@ export default class Plugin implements PluginType { static async list(ncMeta = Noco.ncMeta) { const cachedList = await NocoCache.getList(CacheScope.PLUGIN, []); let { list: pluginList } = cachedList; - if (!pluginList.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 ea55a57f43..b0058dc1ef 100644 --- a/packages/nocodb/src/lib/models/Project.ts +++ b/packages/nocodb/src/lib/models/Project.ts @@ -81,7 +81,8 @@ export default class Project implements ProjectType { // todo: pagination const cachedList = await NocoCache.getList(CacheScope.PROJECT, []); let { list: projectList } = cachedList; - if (!projectList.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 437d8ccf54..c8171d045d 100644 --- a/packages/nocodb/src/lib/models/ProjectUser.ts +++ b/packages/nocodb/src/lib/models/ProjectUser.ts @@ -191,7 +191,8 @@ export default class ProjectUser { userId, ]); let { list: cachedProjectList } = cachedList; - if (cachedProjectList?.length) { + const { isNoneList } = cachedList; + if (!isNoneList && cachedProjectList?.length) { cachedProjectList = cachedProjectList.filter((p) => p.id !== projectId); await NocoCache.setList( CacheScope.USER_PROJECT, @@ -226,8 +227,9 @@ export default class ProjectUser { userId, ]); let { list: projectList } = cachedList; + const { isNoneList } = cachedList; - if (projectList.length) { + if (!isNoneList && projectList.length) { return projectList; } diff --git a/packages/nocodb/src/lib/models/SelectOption.ts b/packages/nocodb/src/lib/models/SelectOption.ts index 86375c7f44..b1523aabbc 100644 --- a/packages/nocodb/src/lib/models/SelectOption.ts +++ b/packages/nocodb/src/lib/models/SelectOption.ts @@ -73,7 +73,8 @@ export default class SelectOption implements SelectOptionType { fk_column_id, ]); let { list: options } = cachedList; - if (!options.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !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 b57e9da3bf..6236d8c107 100644 --- a/packages/nocodb/src/lib/models/View.ts +++ b/packages/nocodb/src/lib/models/View.ts @@ -207,7 +207,8 @@ 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; - if (!viewsList.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !viewsList.length) { viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { condition: { fk_model_id: modelId, @@ -1126,7 +1127,8 @@ export default class View implements ViewType { // get existing cache const cachedList = await NocoCache.getList(scope, [viewId]); const { list: dataList } = cachedList; - if (dataList?.length) { + const { isNoneList } = cachedList; + if (!isNoneList && dataList?.length) { for (const o of dataList) { if (!ignoreColdIds?.length || !ignoreColdIds.includes(o.fk_column_id)) { // set data @@ -1213,6 +1215,7 @@ export default class View implements ViewType { // get existing cache const cachedList = await NocoCache.getList(scope, [viewId]); const { list: dataList } = cachedList; + const { isNoneList } = cachedList; const colsEssentialForView = view.type === ViewTypes.MAP @@ -1221,7 +1224,7 @@ export default class View implements ViewType { const mergedIgnoreColdIds = [...ignoreColdIds, ...colsEssentialForView]; - if (dataList?.length) { + if (!isNoneList && dataList?.length) { for (const o of dataList) { if ( !mergedIgnoreColdIds?.length || @@ -1262,7 +1265,8 @@ 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; - if (!sharedViews.length) { + const { isNoneList } = cachedList; + if (!isNoneList && !sharedViews.length) { sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { xcCondition: { fk_model_id: { From 52bad893149d7a55afe5077e57691aa2bddd5649 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 13 Apr 2023 16:51:23 +0800 Subject: [PATCH 36/37] chore(nocodb): remove console.log --- packages/nocodb/src/lib/cache/RedisCacheMgr.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts index 25c8022fb3..b096f5a068 100644 --- a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts @@ -173,7 +173,6 @@ export default class RedisCacheMgr extends CacheMgr { // Set NONE here so that it won't hit the DB on each page load return this.set(listKey, ['NONE']); } - console.log('HERE'); return Promise.resolve(true); } // fetch existing list From 4abbf4a123e2845ee34a2a4439c93ae35e70c2aa Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 18 Apr 2023 11:40:45 +0800 Subject: [PATCH 37/37] fix(nocodb): set none list for all scopes --- packages/nocodb/src/lib/cache/RedisCacheMgr.ts | 13 ++----------- packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts | 12 ++---------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts index b096f5a068..5fa6f24b69 100644 --- a/packages/nocodb/src/lib/cache/RedisCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisCacheMgr.ts @@ -163,17 +163,8 @@ export default class RedisCacheMgr extends CacheMgr { ? `${this.prefix}:${scope}:list` : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; if (!list.length) { - if ( - [ - CacheScope.FILTER_EXP, - CacheScope.SORT, - CacheScope.MODEL_ROLE_VISIBILITY, - ].includes(scope as CacheScope) - ) { - // Set NONE here so that it won't hit the DB on each page load - return this.set(listKey, ['NONE']); - } - return Promise.resolve(true); + // Set NONE here so that it won't hit the DB on each page load + return this.set(listKey, ['NONE']); } // fetch existing list const listOfGetKeys = diff --git a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts index 0f82bd4185..831d650429 100644 --- a/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts +++ b/packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts @@ -162,16 +162,8 @@ export default class RedisMockCacheMgr extends CacheMgr { ? `${this.prefix}:${scope}:list` : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; if (!list.length) { - if ( - [ - CacheScope.FILTER_EXP, - CacheScope.SORT, - CacheScope.MODEL_ROLE_VISIBILITY, - ].includes(scope as CacheScope) - ) { - return this.set(listKey, ['NONE']); - } - return Promise.resolve(true); + // Set NONE here so that it won't hit the DB on each page load + return this.set(listKey, ['NONE']); } // fetch existing list const listOfGetKeys =