Browse Source

Merge pull request #5430 from nocodb/enhancement/cache-with-empty-list

enhancement: cache on list
pull/5500/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
179cce3be4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      packages/nocodb/src/lib/cache/CacheMgr.ts
  2. 11
      packages/nocodb/src/lib/cache/NocoCache.ts
  3. 37
      packages/nocodb/src/lib/cache/RedisCacheMgr.ts
  4. 46
      packages/nocodb/src/lib/cache/RedisMockCacheMgr.ts
  5. 6
      packages/nocodb/src/lib/models/Base.ts
  6. 82
      packages/nocodb/src/lib/models/Column.ts
  7. 38
      packages/nocodb/src/lib/models/Filter.ts
  8. 18
      packages/nocodb/src/lib/models/FormViewColumn.ts
  9. 18
      packages/nocodb/src/lib/models/GalleryViewColumn.ts
  10. 19
      packages/nocodb/src/lib/models/GridViewColumn.ts
  11. 8
      packages/nocodb/src/lib/models/Hook.ts
  12. 18
      packages/nocodb/src/lib/models/HookFilter.ts
  13. 6
      packages/nocodb/src/lib/models/KanbanViewColumn.ts
  14. 16
      packages/nocodb/src/lib/models/MapViewColumn.ts
  15. 27
      packages/nocodb/src/lib/models/Model.ts
  16. 11
      packages/nocodb/src/lib/models/ModelRoleVisibility.ts
  17. 6
      packages/nocodb/src/lib/models/Plugin.ts
  18. 6
      packages/nocodb/src/lib/models/Project.ts
  19. 12
      packages/nocodb/src/lib/models/ProjectUser.ts
  20. 6
      packages/nocodb/src/lib/models/SelectOption.ts
  21. 6
      packages/nocodb/src/lib/models/Sort.ts
  22. 24
      packages/nocodb/src/lib/models/View.ts

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

@ -4,7 +4,13 @@ export default abstract class CacheMgr {
public abstract del(key: string): Promise<any>; public abstract del(key: string): Promise<any>;
public abstract getAll(pattern: string): Promise<any[]>; public abstract getAll(pattern: string): Promise<any[]>;
public abstract delAll(scope: string, pattern: string): Promise<any[]>; public abstract delAll(scope: string, pattern: string): Promise<any[]>;
public abstract getList(scope: string, list: string[]): Promise<any[]>; public abstract getList(
scope: string,
list: string[]
): Promise<{
list: any[];
isNoneList: boolean;
}>;
public abstract setList( public abstract setList(
scope: string, scope: string,
subListKeys: string[], subListKeys: string[],

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

@ -56,8 +56,15 @@ export default class NocoCache {
public static async getList( public static async getList(
scope: string, scope: string,
subKeys: string[] subKeys: string[]
): Promise<any[]> { ): Promise<{
if (this.cacheDisabled) return Promise.resolve([]); list: any[];
isNoneList: boolean;
}> {
if (this.cacheDisabled)
return Promise.resolve({
list: [],
isNoneList: false,
});
return this.client.getList(scope, subKeys); return this.client.getList(scope, subKeys);
} }

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

@ -114,7 +114,13 @@ export default class RedisCacheMgr extends CacheMgr {
); );
} }
async getList(scope: string, subKeys: string[]): Promise<any[]> { async getList(
scope: string,
subKeys: string[]
): Promise<{
list: any[];
isNoneList: boolean;
}> {
// remove null from arrays // remove null from arrays
subKeys = subKeys.filter((k) => k); subKeys = subKeys.filter((k) => k);
// e.g. key = nc:<orgs>:<scope>:<project_id_1>:<base_id_1>:list // e.g. key = nc:<orgs>:<scope>:<project_id_1>:<base_id_1>:list
@ -125,9 +131,22 @@ export default class RedisCacheMgr 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(`RedisCacheMgr::getList: getting list with key ${key}`); log(`RedisCacheMgr::getList: getting list with key ${key}`);
return Promise.all(
arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT)) const isNoneList = arr.length && arr[0] === 'NONE';
);
if (isNoneList) {
return Promise.resolve({
list: [],
isNoneList,
});
}
return {
list: await Promise.all(
arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT))
),
isNoneList,
};
} }
async setList( async setList(
@ -144,8 +163,8 @@ export default class RedisCacheMgr extends CacheMgr {
? `${this.prefix}:${scope}:list` ? `${this.prefix}:${scope}:list`
: `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`;
if (!list.length) { if (!list.length) {
log(`RedisCacheMgr::setList: List is empty for ${listKey}. Skipping ...`); // Set NONE here so that it won't hit the DB on each page load
return Promise.resolve(true); return this.set(listKey, ['NONE']);
} }
// fetch existing list // fetch existing list
const listOfGetKeys = const listOfGetKeys =
@ -225,7 +244,11 @@ export default class RedisCacheMgr extends CacheMgr {
? `${this.prefix}:${scope}:list` ? `${this.prefix}:${scope}:list`
: `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`;
log(`RedisCacheMgr::appendToList: append key ${key} to ${listKey}`); 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 && list[0] === 'NONE') {
list = [];
await this.del(listKey);
}
list.push(key); list.push(key);
return this.set(listKey, list); return this.set(listKey, list);
} }

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

@ -2,6 +2,7 @@ import debug from 'debug';
import Redis from 'ioredis-mock'; import Redis from 'ioredis-mock';
import { CacheDelDirection, CacheGetType, CacheScope } from '../utils/globals'; import { CacheDelDirection, CacheGetType, CacheScope } from '../utils/globals';
import CacheMgr from './CacheMgr'; import CacheMgr from './CacheMgr';
const log = debug('nc:cache'); const log = debug('nc:cache');
export default class RedisMockCacheMgr extends CacheMgr { export default class RedisMockCacheMgr extends CacheMgr {
@ -102,10 +103,9 @@ export default class RedisMockCacheMgr extends CacheMgr {
`RedisMockCacheMgr::delAll: deleting all keys with pattern ${this.prefix}:${scope}:${pattern}` `RedisMockCacheMgr::delAll: deleting all keys with pattern ${this.prefix}:${scope}:${pattern}`
); );
await Promise.all( await Promise.all(
keys.map( keys.map(async (k) => {
async (k) => await this.deepDel(scope, k, CacheDelDirection.CHILD_TO_PARENT);
await this.deepDel(scope, k, CacheDelDirection.CHILD_TO_PARENT) })
)
); );
return Promise.all( return Promise.all(
keys.map(async (k) => { keys.map(async (k) => {
@ -114,7 +114,13 @@ export default class RedisMockCacheMgr extends CacheMgr {
); );
} }
async getList(scope: string, subKeys: string[]): Promise<any[]> { async getList(
scope: string,
subKeys: string[]
): Promise<{
list: any[];
isNoneList: boolean;
}> {
// remove null from arrays // remove null from arrays
subKeys = subKeys.filter((k) => k); subKeys = subKeys.filter((k) => k);
// e.g. key = nc:<orgs>:<scope>:<project_id_1>:<base_id_1>:list // e.g. key = nc:<orgs>:<scope>:<project_id_1>:<base_id_1>:list
@ -125,9 +131,21 @@ 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}`);
return Promise.all( const isNoneList = arr.length && arr[0] === 'NONE';
arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT))
); if (isNoneList) {
return Promise.resolve({
list: [],
isNoneList,
});
}
return {
list: await Promise.all(
arr.map(async (k) => await this.get(k, CacheGetType.TYPE_OBJECT))
),
isNoneList,
};
} }
async setList( async setList(
@ -144,10 +162,8 @@ export default class RedisMockCacheMgr extends CacheMgr {
? `${this.prefix}:${scope}:list` ? `${this.prefix}:${scope}:list`
: `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`;
if (!list.length) { if (!list.length) {
log( // Set NONE here so that it won't hit the DB on each page load
`RedisMockCacheMgr::setList: List is empty for ${listKey}. Skipping ...` return this.set(listKey, ['NONE']);
);
return Promise.resolve(true);
} }
// fetch existing list // fetch existing list
const listOfGetKeys = const listOfGetKeys =
@ -227,7 +243,11 @@ export default class RedisMockCacheMgr extends CacheMgr {
? `${this.prefix}:${scope}:list` ? `${this.prefix}:${scope}:list`
: `${this.prefix}:${scope}:${subListKeys.join(':')}:list`; : `${this.prefix}:${scope}:${subListKeys.join(':')}:list`;
log(`RedisMockCacheMgr::appendToList: append key ${key} to ${listKey}`); 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 && list[0] === 'NONE') {
list = [];
await this.del(listKey);
}
list.push(key); list.push(key);
return this.set(listKey, list); return this.set(listKey, list);
} }

6
packages/nocodb/src/lib/models/Base.ts

@ -150,10 +150,12 @@ export default class Base implements BaseType {
args: { projectId: string }, args: { projectId: string },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<Base[]> { ): Promise<Base[]> {
let baseDataList = await NocoCache.getList(CacheScope.BASE, [ const cachedList = await NocoCache.getList(CacheScope.BASE, [
args.projectId, args.projectId,
]); ]);
if (!baseDataList.length) { let { list: baseDataList } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !baseDataList.length) {
baseDataList = await ncMeta.metaList2( baseDataList = await ncMeta.metaList2(
args.projectId, args.projectId,
null, null,

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

@ -474,8 +474,12 @@ export default class Column<T = any> implements ColumnType {
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<Column[]> { ): Promise<Column[]> {
let columnsList = await NocoCache.getList(CacheScope.COLUMN, [fk_model_id]); const cachedList = await NocoCache.getList(CacheScope.COLUMN, [
if (!columnsList.length) { fk_model_id,
]);
let { list: columnsList } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !columnsList.length) {
columnsList = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, { columnsList = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, {
condition: { condition: {
fk_model_id, fk_model_id,
@ -627,8 +631,10 @@ export default class Column<T = any> implements ColumnType {
// get lookup columns and delete // get lookup columns and delete
{ {
let lookups = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]);
if (!lookups.length) { let { list: lookups } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !lookups.length) {
lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, {
condition: { fk_lookup_column_id: id }, condition: { fk_lookup_column_id: id },
}); });
@ -640,8 +646,10 @@ export default class Column<T = any> implements ColumnType {
// get rollup column and delete // get rollup column and delete
{ {
let rollups = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]); const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]);
if (!rollups.length) { let { list: rollups } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !rollups.length) {
rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, { rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, {
condition: { fk_rollup_column_id: id }, condition: { fk_rollup_column_id: id },
}); });
@ -652,10 +660,12 @@ export default class Column<T = any> implements ColumnType {
} }
{ {
let formulaColumns = await NocoCache.getList(CacheScope.COLUMN, [ const cachedList = await NocoCache.getList(CacheScope.COLUMN, [
col.fk_model_id, col.fk_model_id,
]); ]);
if (!formulaColumns.length) { let { list: formulaColumns } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !formulaColumns.length) {
formulaColumns = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, { formulaColumns = await ncMeta.metaList2(null, null, MetaTable.COLUMNS, {
condition: { condition: {
fk_model_id: col.fk_model_id, fk_model_id: col.fk_model_id,
@ -682,33 +692,43 @@ export default class Column<T = any> implements ColumnType {
// if relation column check lookup and rollup and delete // if relation column check lookup and rollup and delete
if (col.uidt === UITypes.LinkToAnotherRecord) { if (col.uidt === UITypes.LinkToAnotherRecord) {
// get lookup columns using relation and delete {
let lookups = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]); // get lookup columns using relation and delete
if (!lookups.length) { const cachedList = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]);
lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, { let { list: lookups } = cachedList;
condition: { fk_relation_column_id: id }, const { isNoneList } = cachedList;
}); if (!isNoneList && !lookups.length) {
} lookups = await ncMeta.metaList2(null, null, MetaTable.COL_LOOKUP, {
for (const lookup of lookups) { condition: { fk_relation_column_id: id },
await Column.delete(lookup.fk_column_id, ncMeta); });
}
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]); // get rollup columns using relation and delete
if (!rollups.length) { const cachedList = await NocoCache.getList(CacheScope.COL_ROLLUP, [id]);
rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, { let { list: rollups } = cachedList;
condition: { fk_relation_column_id: id }, const { isNoneList } = cachedList;
}); if (!isNoneList && !rollups.length) {
} rollups = await ncMeta.metaList2(null, null, MetaTable.COL_ROLLUP, {
for (const rollup of rollups) { condition: { fk_relation_column_id: id },
await Column.delete(rollup.fk_column_id, ncMeta); });
}
for (const rollup of rollups) {
await Column.delete(rollup.fk_column_id, ncMeta);
}
} }
} }
// delete sorts // delete sorts
{ {
let sorts = await NocoCache.getList(CacheScope.SORT, [id]); const cachedList = await NocoCache.getList(CacheScope.SORT, [id]);
if (!sorts.length) { let { list: sorts } = cachedList;
const { isNoneList } = cachedList;
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,
@ -721,8 +741,10 @@ export default class Column<T = any> implements ColumnType {
} }
// delete filters // delete filters
{ {
let filters = await NocoCache.getList(CacheScope.FILTER_EXP, [id]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [id]);
if (!filters.length) { let { list: filters } = cachedList;
const { isNoneList } = cachedList;
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,

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

@ -326,10 +326,12 @@ export default class Filter implements FilterType {
public async getChildren(ncMeta = Noco.ncMeta): Promise<Filter[]> { public async getChildren(ncMeta = Noco.ncMeta): Promise<Filter[]> {
if (this.children) return this.children; if (this.children) return this.children;
if (!this.is_group) return null; if (!this.is_group) return null;
let childFilters = await NocoCache.getList(CacheScope.FILTER_EXP, [ const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [
this.id, this.id,
]); ]);
if (!childFilters.length) { let { list: childFilters } = cachedList;
const { isNoneList } = cachedList;
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,
@ -369,10 +371,12 @@ export default class Filter implements FilterType {
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<FilterType> { ): Promise<FilterType> {
let filters = await NocoCache.getList(CacheScope.FILTER_EXP, [ const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [
viewId || hookId, viewId || hookId,
]); ]);
if (!filters.length) { let { list: filters } = cachedList;
const { isNoneList } = cachedList;
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: {
@ -480,8 +484,10 @@ export default class Filter implements FilterType {
{ viewId }: { viewId: any }, { viewId }: { viewId: any },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
) { ) {
let filterObjs = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]);
if (!filterObjs.length) { let { list: filterObjs } = cachedList;
const { isNoneList } = cachedList;
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: {
@ -499,8 +505,10 @@ export default class Filter implements FilterType {
{ hookId }: { hookId: any }, { hookId }: { hookId: any },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
) { ) {
let filterObjs = await NocoCache.getList(CacheScope.FILTER_EXP, [hookId]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [hookId]);
if (!filterObjs.length) { let { list: filterObjs } = cachedList;
const { isNoneList } = cachedList;
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: {
@ -520,8 +528,12 @@ export default class Filter implements FilterType {
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
) { ) {
let filterObjs = await NocoCache.getList(CacheScope.FILTER_EXP, [parentId]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [
if (!filterObjs.length) { parentId,
]);
let { list: filterObjs } = cachedList;
const { isNoneList } = cachedList;
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,
@ -546,11 +558,13 @@ export default class Filter implements FilterType {
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
) { ) {
let filterObjs = await NocoCache.getList(CacheScope.FILTER_EXP, [ const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [
hookId, hookId,
parentId, parentId,
]); ]);
if (!filterObjs.length) { let { list: filterObjs } = cachedList;
const { isNoneList } = cachedList;
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,

18
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); 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 cache is not present skip pushing it into the list to avoid unexpected behaviour
if ( const { list } = await NocoCache.getList(CacheScope.FORM_VIEW_COLUMN, [
( column.fk_view_id,
await NocoCache.getList(CacheScope.FORM_VIEW_COLUMN, [ ]);
column.fk_view_id,
]) if (list?.length)
)?.length
)
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.FORM_VIEW_COLUMN, CacheScope.FORM_VIEW_COLUMN,
[column.fk_view_id], [column.fk_view_id],
@ -119,10 +117,12 @@ export default class FormViewColumn implements FormColumnType {
viewId: string, viewId: string,
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<FormViewColumn[]> { ): Promise<FormViewColumn[]> {
let viewColumns = await NocoCache.getList(CacheScope.FORM_VIEW_COLUMN, [ const cachedList = await NocoCache.getList(CacheScope.FORM_VIEW_COLUMN, [
viewId, viewId,
]); ]);
if (!viewColumns.length) { let { list: viewColumns } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !viewColumns.length) {
viewColumns = await ncMeta.metaList2( viewColumns = await ncMeta.metaList2(
null, null,
null, null,

18
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 cache is not present skip pushing it into the list to avoid unexpected behaviour
if ( const { list } = await NocoCache.getList(CacheScope.GALLERY_VIEW_COLUMN, [
( column.fk_view_id,
await NocoCache.getList(CacheScope.GALLERY_VIEW_COLUMN, [ ]);
column.fk_view_id,
]) if (list?.length)
)?.length
)
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.GALLERY_VIEW_COLUMN, CacheScope.GALLERY_VIEW_COLUMN,
[column.fk_view_id], [column.fk_view_id],
@ -99,10 +97,12 @@ export default class GalleryViewColumn {
viewId: string, viewId: string,
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<GalleryViewColumn[]> { ): Promise<GalleryViewColumn[]> {
let views = await NocoCache.getList(CacheScope.GALLERY_VIEW_COLUMN, [ const cachedList = await NocoCache.getList(CacheScope.GALLERY_VIEW_COLUMN, [
viewId, viewId,
]); ]);
if (!views.length) { let { list: views } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !views.length) {
views = await ncMeta.metaList2( views = await ncMeta.metaList2(
null, null,
null, null,

19
packages/nocodb/src/lib/models/GridViewColumn.ts

@ -24,8 +24,12 @@ export default class GridViewColumn implements GridColumnType {
viewId: string, viewId: string,
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<GridViewColumn[]> { ): Promise<GridViewColumn[]> {
let views = await NocoCache.getList(CacheScope.GRID_VIEW_COLUMN, [viewId]); const cachedList = await NocoCache.getList(CacheScope.GRID_VIEW_COLUMN, [
if (!views.length) { viewId,
]);
let { list: views } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !views.length) {
views = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, { views = await ncMeta.metaList2(null, null, MetaTable.GRID_VIEW_COLUMNS, {
condition: { condition: {
fk_view_id: viewId, 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); 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 cache is not present skip pushing it into the list to avoid unexpected behaviour
if ( const { list } = await NocoCache.getList(CacheScope.GRID_VIEW_COLUMN, [
( column.fk_view_id,
await NocoCache.getList(CacheScope.GRID_VIEW_COLUMN, [ ]);
column.fk_view_id, if (list.length)
])
)?.length
)
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.GRID_VIEW_COLUMN, CacheScope.GRID_VIEW_COLUMN,
[column.fk_view_id], [column.fk_view_id],

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

@ -85,8 +85,12 @@ export default class Hook implements HookType {
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
) { ) {
let hooks = await NocoCache.getList(CacheScope.HOOK, [param.fk_model_id]); const cachedList = await NocoCache.getList(CacheScope.HOOK, [
if (!hooks.length) { param.fk_model_id,
]);
let { list: hooks } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !hooks.length) {
hooks = await ncMeta.metaList(null, null, MetaTable.HOOKS, { hooks = await ncMeta.metaList(null, null, MetaTable.HOOKS, {
condition: { condition: {
fk_model_id: param.fk_model_id, fk_model_id: param.fk_model_id,

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

@ -205,10 +205,12 @@ export default class Filter {
public async getChildren(ncMeta = Noco.ncMeta): Promise<Filter[]> { public async getChildren(ncMeta = Noco.ncMeta): Promise<Filter[]> {
if (this.children) return this.children; if (this.children) return this.children;
if (!this.is_group) return null; if (!this.is_group) return null;
let childFilters = await NocoCache.getList(CacheScope.FILTER_EXP, [ const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [
this.id, this.id,
]); ]);
if (!childFilters.length) { let { list: childFilters } = cachedList;
const { isNoneList } = cachedList;
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,
@ -243,8 +245,10 @@ export default class Filter {
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<FilterType> { ): Promise<FilterType> {
let filters = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]);
if (!filters.length) { let { list: filters } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !filters.length) {
filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, { filters = await ncMeta.metaList2(null, null, MetaTable.FILTER_EXP, {
condition: { fk_view_id: viewId }, condition: { fk_view_id: viewId },
}); });
@ -327,8 +331,10 @@ export default class Filter {
{ viewId }: { viewId: any }, { viewId }: { viewId: any },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
) { ) {
let filterObjs = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]); const cachedList = await NocoCache.getList(CacheScope.FILTER_EXP, [viewId]);
if (!filterObjs.length) { let { list: filterObjs } = cachedList;
const { isNoneList } = cachedList;
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 },
}); });

6
packages/nocodb/src/lib/models/KanbanViewColumn.ts

@ -85,10 +85,12 @@ export default class KanbanViewColumn implements KanbanColumnType {
viewId: string, viewId: string,
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<KanbanViewColumn[]> { ): Promise<KanbanViewColumn[]> {
let views = await NocoCache.getList(CacheScope.KANBAN_VIEW_COLUMN, [ const cachedList = await NocoCache.getList(CacheScope.KANBAN_VIEW_COLUMN, [
viewId, viewId,
]); ]);
if (!views.length) { let { list: views } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !views.length) {
views = await ncMeta.metaList2( views = await ncMeta.metaList2(
null, null,
null, null,

16
packages/nocodb/src/lib/models/MapViewColumn.ts

@ -67,10 +67,10 @@ export default class MapViewColumn {
await NocoCache.set(`${CacheScope.MAP_VIEW_COLUMN}:${fk_column_id}`, id); 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 cache is not present skip pushing it into the list to avoid unexpected behaviour
if ( const { list } = await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [
(await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [column.fk_view_id])) column.fk_view_id,
?.length ]);
) if (list?.length)
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.MAP_VIEW_COLUMN, CacheScope.MAP_VIEW_COLUMN,
[column.fk_view_id], [column.fk_view_id],
@ -84,8 +84,12 @@ export default class MapViewColumn {
viewId: string, viewId: string,
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<MapViewColumn[]> { ): Promise<MapViewColumn[]> {
let views = await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [viewId]); const cachedList = await NocoCache.getList(CacheScope.MAP_VIEW_COLUMN, [
if (!views.length) { viewId,
]);
let { list: views } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !views.length) {
views = await ncMeta.metaList2(null, null, MetaTable.MAP_VIEW_COLUMNS, { views = await ncMeta.metaList2(null, null, MetaTable.MAP_VIEW_COLUMNS, {
condition: { condition: {
fk_view_id: viewId, fk_view_id: viewId,

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

@ -160,13 +160,10 @@ export default class Model implements TableType {
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<Model[]> { ): Promise<Model[]> {
let modelList = []; const cachedList = await NocoCache.getList(CacheScope.MODEL, [project_id]);
if (base_id) { let { list: modelList } = cachedList;
await NocoCache.getList(CacheScope.MODEL, [project_id, base_id]); const { isNoneList } = cachedList;
} else { if (!isNoneList && !modelList.length) {
await NocoCache.getList(CacheScope.MODEL, [project_id]);
}
if (!modelList.length) {
modelList = await ncMeta.metaList2( modelList = await ncMeta.metaList2(
project_id, project_id,
base_id, base_id,
@ -183,15 +180,7 @@ export default class Model implements TableType {
model.meta = parseMetaProp(model); model.meta = parseMetaProp(model);
} }
if (base_id) { await NocoCache.setList(CacheScope.MODEL, [project_id], modelList);
await NocoCache.setList(
CacheScope.MODEL,
[project_id, base_id],
modelList
);
} else {
await NocoCache.setList(CacheScope.MODEL, [project_id], modelList);
}
} }
modelList.sort( modelList.sort(
(a, b) => (a, b) =>
@ -211,11 +200,13 @@ export default class Model implements TableType {
}, },
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<Model[]> { ): Promise<Model[]> {
let modelList = await NocoCache.getList(CacheScope.MODEL, [ const cachedList = await NocoCache.getList(CacheScope.MODEL, [
project_id, project_id,
db_alias, db_alias,
]); ]);
if (!modelList.length) { let { list: modelList } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !modelList.length) {
modelList = await ncMeta.metaList2( modelList = await ncMeta.metaList2(
project_id, project_id,
db_alias, db_alias,

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

@ -24,10 +24,13 @@ export default class ModelRoleVisibility implements ModelRoleVisibilityType {
} }
static async list(projectId): Promise<ModelRoleVisibility[]> { static async list(projectId): Promise<ModelRoleVisibility[]> {
let data = await NocoCache.getList(CacheScope.MODEL_ROLE_VISIBILITY, [ const cachedList = await NocoCache.getList(
projectId, CacheScope.MODEL_ROLE_VISIBILITY,
]); [projectId]
if (!data.length) { );
let { list: data } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !data.length) {
data = await Noco.ncMeta.metaList2( data = await Noco.ncMeta.metaList2(
projectId, projectId,
null, null,

6
packages/nocodb/src/lib/models/Plugin.ts

@ -43,8 +43,10 @@ export default class Plugin implements PluginType {
} }
static async list(ncMeta = Noco.ncMeta) { static async list(ncMeta = Noco.ncMeta) {
let pluginList = await NocoCache.getList(CacheScope.PLUGIN, []); const cachedList = await NocoCache.getList(CacheScope.PLUGIN, []);
if (!pluginList.length) { let { list: pluginList } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !pluginList.length) {
pluginList = await ncMeta.metaList2(null, null, MetaTable.PLUGIN); pluginList = await ncMeta.metaList2(null, null, MetaTable.PLUGIN);
await NocoCache.setList(CacheScope.PLUGIN, [], pluginList); await NocoCache.setList(CacheScope.PLUGIN, [], pluginList);
} }

6
packages/nocodb/src/lib/models/Project.ts

@ -79,8 +79,10 @@ export default class Project implements ProjectType {
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<Project[]> { ): Promise<Project[]> {
// todo: pagination // todo: pagination
let projectList = await NocoCache.getList(CacheScope.PROJECT, []); const cachedList = await NocoCache.getList(CacheScope.PROJECT, []);
if (!projectList.length) { let { list: projectList } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !projectList.length) {
projectList = await ncMeta.metaList2(null, null, MetaTable.PROJECT, { projectList = await ncMeta.metaList2(null, null, MetaTable.PROJECT, {
xcCondition: { xcCondition: {
_or: [ _or: [

12
packages/nocodb/src/lib/models/ProjectUser.ts

@ -187,10 +187,12 @@ export default class ProjectUser {
} }
// remove project from user project list cache // remove project from user project list cache
let cachedProjectList = await NocoCache.getList(CacheScope.USER_PROJECT, [ const cachedList = await NocoCache.getList(CacheScope.USER_PROJECT, [
userId, userId,
]); ]);
if (cachedProjectList?.length) { let { list: cachedProjectList } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && cachedProjectList?.length) {
cachedProjectList = cachedProjectList.filter((p) => p.id !== projectId); cachedProjectList = cachedProjectList.filter((p) => p.id !== projectId);
await NocoCache.setList( await NocoCache.setList(
CacheScope.USER_PROJECT, CacheScope.USER_PROJECT,
@ -221,11 +223,13 @@ export default class ProjectUser {
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<ProjectType[]> { ): Promise<ProjectType[]> {
// todo: pagination // todo: pagination
let projectList = await NocoCache.getList(CacheScope.USER_PROJECT, [ const cachedList = await NocoCache.getList(CacheScope.USER_PROJECT, [
userId, userId,
]); ]);
let { list: projectList } = cachedList;
const { isNoneList } = cachedList;
if (projectList.length) { if (!isNoneList && projectList.length) {
return projectList; return projectList;
} }

6
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) { 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, fk_column_id,
]); ]);
if (!options.length) { let { list: options } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !options.length) {
options = await ncMeta.metaList2( options = await ncMeta.metaList2(
null, //, null, //,
null, //model.db_alias, null, //model.db_alias,

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

@ -114,8 +114,10 @@ export default class Sort {
ncMeta = Noco.ncMeta ncMeta = Noco.ncMeta
): Promise<Sort[]> { ): Promise<Sort[]> {
if (!viewId) return null; if (!viewId) return null;
let sortList = await NocoCache.getList(CacheScope.SORT, [viewId]); const cachedList = await NocoCache.getList(CacheScope.SORT, [viewId]);
if (!sortList.length) { let { list: sortList } = cachedList;
const { isNoneList } = cachedList;
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: {

24
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) { public static async list(modelId: string, ncMeta = Noco.ncMeta) {
let viewsList = await NocoCache.getList(CacheScope.VIEW, [modelId]); const cachedList = await NocoCache.getList(CacheScope.VIEW, [modelId]);
if (!viewsList.length) { let { list: viewsList } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !viewsList.length) {
viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, {
condition: { condition: {
fk_model_id: modelId, fk_model_id: modelId,
@ -1123,8 +1125,10 @@ export default class View implements ViewType {
); );
// get existing cache // get existing cache
const dataList = await NocoCache.getList(scope, [viewId]); const cachedList = await NocoCache.getList(scope, [viewId]);
if (dataList?.length) { const { list: dataList } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && dataList?.length) {
for (const o of dataList) { for (const o of dataList) {
if (!ignoreColdIds?.length || !ignoreColdIds.includes(o.fk_column_id)) { if (!ignoreColdIds?.length || !ignoreColdIds.includes(o.fk_column_id)) {
// set data // set data
@ -1209,7 +1213,9 @@ export default class View implements ViewType {
} }
// get existing cache // get existing cache
const dataList = await NocoCache.getList(scope, [viewId]); const cachedList = await NocoCache.getList(scope, [viewId]);
const { list: dataList } = cachedList;
const { isNoneList } = cachedList;
const colsEssentialForView = const colsEssentialForView =
view.type === ViewTypes.MAP view.type === ViewTypes.MAP
@ -1218,7 +1224,7 @@ export default class View implements ViewType {
const mergedIgnoreColdIds = [...ignoreColdIds, ...colsEssentialForView]; const mergedIgnoreColdIds = [...ignoreColdIds, ...colsEssentialForView];
if (dataList?.length) { if (!isNoneList && dataList?.length) {
for (const o of dataList) { for (const o of dataList) {
if ( if (
!mergedIgnoreColdIds?.length || !mergedIgnoreColdIds?.length ||
@ -1257,8 +1263,10 @@ export default class View implements ViewType {
} }
static async shareViewList(tableId, ncMeta = Noco.ncMeta) { static async shareViewList(tableId, ncMeta = Noco.ncMeta) {
let sharedViews = await NocoCache.getList(CacheScope.VIEW, [tableId]); const cachedList = await NocoCache.getList(CacheScope.VIEW, [tableId]);
if (!sharedViews.length) { let { list: sharedViews } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !sharedViews.length) {
sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEWS, {
xcCondition: { xcCondition: {
fk_model_id: { fk_model_id: {

Loading…
Cancel
Save