Browse Source

refactor(nocodb): rename to isNoneList

pull/5430/head
Wing-Kam Wong 2 years ago
parent
commit
a4be82b391
  1. 2
      packages/nocodb/src/lib/cache/CacheMgr.ts
  2. 4
      packages/nocodb/src/lib/cache/NocoCache.ts
  3. 12
      packages/nocodb/src/lib/cache/RedisCacheMgr.ts
  4. 10
      packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts
  5. 8
      packages/nocodb/src/lib/models/Column.ts
  6. 24
      packages/nocodb/src/lib/models/Filter.ts
  7. 4
      packages/nocodb/src/lib/models/ModelRoleVisibility.ts
  8. 4
      packages/nocodb/src/lib/models/Sort.ts

2
packages/nocodb/src/lib/cache/CacheMgr.ts vendored

@ -9,7 +9,7 @@ export default abstract class CacheMgr {
list: string[] list: string[]
): Promise<{ ): Promise<{
list: any[]; list: any[];
isEmptyList: boolean; isNoneList: boolean;
}>; }>;
public abstract setList( public abstract setList(
scope: string, scope: string,

4
packages/nocodb/src/lib/cache/NocoCache.ts vendored

@ -58,12 +58,12 @@ export default class NocoCache {
subKeys: string[] subKeys: string[]
): Promise<{ ): Promise<{
list: any[]; list: any[];
isEmptyList: boolean; isNoneList: boolean;
}> { }> {
if (this.cacheDisabled) if (this.cacheDisabled)
return Promise.resolve({ return Promise.resolve({
list: [], list: [],
isEmptyList: false, isNoneList: false,
}); });
return this.client.getList(scope, subKeys); return this.client.getList(scope, subKeys);
} }

12
packages/nocodb/src/lib/cache/RedisCacheMgr.ts vendored

@ -119,7 +119,7 @@ export default class RedisCacheMgr extends CacheMgr {
subKeys: string[] subKeys: string[]
): Promise<{ ): Promise<{
list: any[]; list: any[];
isEmptyList: boolean; isNoneList: boolean;
}> { }> {
// remove null from arrays // remove null from arrays
subKeys = subKeys.filter((k) => k); subKeys = subKeys.filter((k) => k);
@ -132,12 +132,12 @@ export default class RedisCacheMgr extends CacheMgr {
const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || [];
log(`RedisCacheMgr::getList: getting list with key ${key}`); 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({ return Promise.resolve({
list: [], list: [],
isEmptyList, isNoneList,
}); });
} }
@ -145,7 +145,7 @@ export default class RedisCacheMgr extends CacheMgr {
list: await Promise.all( list: await Promise.all(
arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) 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, CacheScope.MODEL_ROLE_VISIBILITY,
].includes(scope as CacheScope) ].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 this.set(listKey, ['NONE']);
} }
console.log('HERE');
return Promise.resolve(true); return Promise.resolve(true);
} }
// fetch existing list // fetch existing list

10
packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts vendored

@ -119,7 +119,7 @@ export default class RedisMockCacheMgr extends CacheMgr {
subKeys: string[] subKeys: string[]
): Promise<{ ): Promise<{
list: any[]; list: any[];
isEmptyList: boolean; isNoneList: boolean;
}> { }> {
// remove null from arrays // remove null from arrays
subKeys = subKeys.filter((k) => k); subKeys = subKeys.filter((k) => k);
@ -131,12 +131,12 @@ export default class RedisMockCacheMgr extends CacheMgr {
// e.g. arr = ["nc:<orgs>:<scope>:<model_id_1>", "nc:<orgs>:<scope>:<model_id_2>"] // e.g. arr = ["nc:<orgs>:<scope>:<model_id_1>", "nc:<orgs>:<scope>:<model_id_2>"]
const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || []; const arr = (await this.get(key, CacheGetType.TYPE_ARRAY)) || [];
log(`RedisMockCacheMgr::getList: getting list with key ${key}`); 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({ return Promise.resolve({
list: [], list: [],
isEmptyList, isNoneList,
}); });
} }
@ -144,7 +144,7 @@ export default class RedisMockCacheMgr extends CacheMgr {
list: await Promise.all( list: await Promise.all(
arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT))
), ),
isEmptyList, isNoneList,
}; };
} }

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

@ -721,8 +721,8 @@ export default class Column<T = any> implements ColumnType {
{ {
const cachedList = await NocoCache.getList(CacheScope.SORT, [id]); const cachedList = await NocoCache.getList(CacheScope.SORT, [id]);
let { list: sorts } = cachedList; let { list: sorts } = cachedList;
const { isEmptyList } = cachedList; const { isNoneList } = cachedList;
if (!isEmptyList && !sorts.length) { if (!isNoneList && !sorts.length) {
sorts = await ncMeta.metaList2(null, null, MetaTable.SORT, { sorts = await ncMeta.metaList2(null, null, MetaTable.SORT, {
condition: { condition: {
fk_column_id: id, fk_column_id: id,
@ -737,8 +737,8 @@ export default class Column<T = any> implements ColumnType {
{ {
const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [id]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [id]);
let { list: filters } = cachedList; let { list: filters } = cachedList;
const { isEmptyList } = cachedList; const { isNoneList } = cachedList;
if (!isEmptyList && !filters.length) { if (!isNoneList && !filters.length) {
filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: { condition: {
fk_column_id: id, fk_column_id: id,

24
packages/nocodb/src/lib/models/Filter.ts

@ -330,8 +330,8 @@ export default class Filter implements FilterType {
this.id, this.id,
]); ]);
let { list: childFilters } = cachedList; let { list: childFilters } = cachedList;
const { isEmptyList } = cachedList; const { isNoneList } = cachedList;
if (!isEmptyList && !childFilters.length) { if (!isNoneList && !childFilters.length) {
childFilters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { childFilters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: { condition: {
fk_parent_id: this.id, fk_parent_id: this.id,
@ -375,8 +375,8 @@ export default class Filter implements FilterType {
viewId || hookId, viewId || hookId,
]); ]);
let { list: filters } = cachedList; let { list: filters } = cachedList;
const { isEmptyList } = cachedList; const { isNoneList } = cachedList;
if (!isEmptyList && !filters.length) { if (!isNoneList && !filters.length) {
filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: viewId ? { fk_view_id: viewId } : { fk_hook_id: hookId }, condition: viewId ? { fk_view_id: viewId } : { fk_hook_id: hookId },
orderBy: { orderBy: {
@ -486,8 +486,8 @@ export default class Filter implements FilterType {
) { ) {
const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]);
let { list: filterObjs } = cachedList; let { list: filterObjs } = cachedList;
const { isEmptyList } = cachedList; const { isNoneList } = cachedList;
if (!isEmptyList && !filterObjs.length) { if (!isNoneList && !filterObjs.length) {
filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: { fk_view_id: viewId }, condition: { fk_view_id: viewId },
orderBy: { orderBy: {
@ -507,8 +507,8 @@ export default class Filter implements FilterType {
) { ) {
const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [hookId]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [hookId]);
let { list: filterObjs } = cachedList; let { list: filterObjs } = cachedList;
const { isEmptyList } = cachedList; const { isNoneList } = cachedList;
if (!isEmptyList && !filterObjs.length) { if (!isNoneList && !filterObjs.length) {
filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: { fk_hook_id: hookId }, condition: { fk_hook_id: hookId },
orderBy: { orderBy: {
@ -532,8 +532,8 @@ export default class Filter implements FilterType {
parentId, parentId,
]); ]);
let { list: filterObjs } = cachedList; let { list: filterObjs } = cachedList;
const { isEmptyList } = cachedList; const { isNoneList } = cachedList;
if (!isEmptyList && !filterObjs.length) { if (!isNoneList && !filterObjs.length) {
filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: { condition: {
fk_parent_id: parentId, fk_parent_id: parentId,
@ -563,8 +563,8 @@ export default class Filter implements FilterType {
parentId, parentId,
]); ]);
let { list: filterObjs } = cachedList; let { list: filterObjs } = cachedList;
const { isEmptyList } = cachedList; const { isNoneList } = cachedList;
if (!isEmptyList && !filterObjs.length) { if (!isNoneList && !filterObjs.length) {
filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { filterObjs = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: { condition: {
fk_parent_id: parentId, fk_parent_id: parentId,

4
packages/nocodb/src/lib/models/ModelRoleVisibility.ts

@ -29,8 +29,8 @@ export default class ModelRoleVisibility implements ModelRoleVisibilityType {
[projectId] [projectId]
); );
let { list: data } = cachedList; let { list: data } = cachedList;
const { isEmptyList } = cachedList; const { isNoneList } = cachedList;
if (!isEmptyList && !data.length) { if (!isNoneList && !data.length) {
data = await Noco.ncMeta.metaList2( data = await Noco.ncMeta.metaList2(
projectId, projectId,
null, null,

4
packages/nocodb/src/lib/models/Sort.ts

@ -116,8 +116,8 @@ export default class Sort {
if (!viewId) return null; if (!viewId) return null;
const cachedList = await NocoCache.getList(CacheScope.SORT, [viewId]); const cachedList = await NocoCache.getList(CacheScope.SORT, [viewId]);
let { list: sortList } = cachedList; let { list: sortList } = cachedList;
const { isEmptyList } = cachedList; const { isNoneList } = cachedList;
if (!isEmptyList && !sortList.length) { if (!isNoneList && !sortList.length) {
sortList = await ncMeta.metaList2(null, null, MetaTable.SORT, { sortList = await ncMeta.metaList2(null, null, MetaTable.SORT, {
condition: { fk_view_id: viewId }, condition: { fk_view_id: viewId },
orderBy: { orderBy: {

Loading…
Cancel
Save