Browse Source

Merge pull request #5707 from nocodb/fix/model-cache

fix(nocodb): model list cache
pull/5715/head
Raju Udava 2 years ago committed by GitHub
parent
commit
90c102ddd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      packages/nocodb/src/models/Model.ts

34
packages/nocodb/src/models/Model.ts

@ -135,7 +135,15 @@ export default class Model implements TableType {
MetaTable.MODELS, MetaTable.MODELS,
insertObj, insertObj,
); );
if (baseId) {
await NocoCache.appendToList(
CacheScope.MODEL,
[projectId, baseId],
`${CacheScope.MODEL}:${id}`,
);
}
// cater cases where baseId is not required
// e.g. xcVisibilityMetaGet
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.MODEL, CacheScope.MODEL,
[projectId], [projectId],
@ -169,7 +177,10 @@ export default class Model implements TableType {
}, },
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
): Promise<Model[]> { ): Promise<Model[]> {
const cachedList = await NocoCache.getList(CacheScope.MODEL, [project_id]); const cachedList = await NocoCache.getList(CacheScope.MODEL, [
project_id,
base_id,
]);
let { list: modelList } = cachedList; let { list: modelList } = cachedList;
const { isNoneList } = cachedList; const { isNoneList } = cachedList;
if (!isNoneList && !modelList.length) { if (!isNoneList && !modelList.length) {
@ -189,7 +200,11 @@ export default class Model implements TableType {
model.meta = parseMetaProp(model); model.meta = parseMetaProp(model);
} }
await NocoCache.setList(CacheScope.MODEL, [project_id], modelList); await NocoCache.setList(
CacheScope.MODEL,
[project_id, base_id],
modelList,
);
} }
modelList.sort( modelList.sort(
(a, b) => (a, b) =>
@ -683,13 +698,13 @@ export default class Model implements TableType {
}, },
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
const cacheKey = base_id
? `${CacheScope.MODEL}:${project_id}:${base_id}:${aliasOrId}`
: `${CacheScope.MODEL}:${project_id}:${aliasOrId}`;
const modelId = const modelId =
project_id && project_id &&
aliasOrId && aliasOrId &&
(await NocoCache.get( (await NocoCache.get(cacheKey, CacheGetType.TYPE_OBJECT));
`${CacheScope.MODEL}:${project_id}:${aliasOrId}`,
CacheGetType.TYPE_OBJECT,
));
if (!modelId) { if (!modelId) {
const model = base_id const model = base_id
? await ncMeta.metaGet2( ? await ncMeta.metaGet2(
@ -735,10 +750,7 @@ export default class Model implements TableType {
}, },
); );
if (model) { if (model) {
await NocoCache.set( await NocoCache.set(cacheKey, model.id);
`${CacheScope.MODEL}:${project_id}:${aliasOrId}`,
model.id,
);
await NocoCache.set(`${CacheScope.MODEL}:${model.id}`, model); await NocoCache.set(`${CacheScope.MODEL}:${model.id}`, model);
} }
return model && new Model(model); return model && new Model(model);

Loading…
Cancel
Save