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[]
): Promise<{
list: any[];
isEmptyList: boolean;
isNoneList: boolean;
}>;
public abstract setList(
scope: string,

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

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

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

@ -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

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

@ -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:<orgs>:<scope>:<model_id_1>", "nc:<orgs>:<scope>:<model_id_2>"]
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,
};
}

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]);
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<T = any> 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,

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

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

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

Loading…
Cancel
Save