Browse Source

fix: avoid del calls before deep del & delete meta before cache

pull/7464/head
mertmit 11 months ago
parent
commit
81fb3f79c3
  1. 4
      packages/nocodb/src/models/Column.ts
  2. 23
      packages/nocodb/src/models/Model.ts
  3. 13
      packages/nocodb/src/models/ModelRoleVisibility.ts
  4. 4
      packages/nocodb/src/models/Sort.ts
  5. 17
      packages/nocodb/src/models/Source.ts
  6. 14
      packages/nocodb/src/models/View.ts

4
packages/nocodb/src/models/Column.ts

@ -854,7 +854,6 @@ export default class Column<T = any> implements ColumnType {
`${CacheScope.GRID_VIEW_COLUMN}:${gridViewColumnId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
await NocoCache.del(`${CacheScope.GRID_VIEW_COLUMN}:${col.id}`);
}
// Form View Columns
@ -871,7 +870,6 @@ export default class Column<T = any> implements ColumnType {
`${CacheScope.FORM_VIEW_COLUMN}:${formViewColumnId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
await NocoCache.del(`${CacheScope.FORM_VIEW_COLUMN}:${col.id}`);
}
// Kanban View Columns
@ -888,7 +886,6 @@ export default class Column<T = any> implements ColumnType {
`${CacheScope.KANBAN_VIEW_COLUMN}:${kanbanViewColumnId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
await NocoCache.del(`${CacheScope.KANBAN_VIEW_COLUMN}:${col.id}`);
}
// Gallery View Column
@ -905,7 +902,6 @@ export default class Column<T = any> implements ColumnType {
`${CacheScope.GALLERY_VIEW_COLUMN}:${galleryViewColumnId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
await NocoCache.del(`${CacheScope.GALLERY_VIEW_COLUMN}:${col.id}`);
}
// Get LTAR columns in which current column is referenced as foreign key

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

@ -213,6 +213,8 @@ export default class Model implements TableType {
[base_id, source_id],
modelList,
);
await NocoCache.setList(CacheScope.MODEL, [base_id], modelList);
}
modelList.sort(
(a, b) =>
@ -496,8 +498,13 @@ export default class Model implements TableType {
);
await ncMeta.metaDelete(null, null, MetaTable.MODELS, this.id);
await NocoCache.del(`${CacheScope.MODEL}:${this.base_id}:${this.id}`);
await NocoCache.del(`${CacheScope.MODEL}:${this.base_id}:${this.title}`);
// delete alias cache
await NocoCache.del([
`${CacheScope.MODEL_ALIAS}:${this.base_id}:${this.id}`,
`${CacheScope.MODEL_ALIAS}:${this.base_id}:${this.source_id}:${this.id}`,
`${CacheScope.MODEL_ALIAS}:${this.base_id}:${this.title}`,
`${CacheScope.MODEL_ALIAS}:${this.base_id}:${this.source_id}:${this.title}`,
]);
return true;
}
@ -635,12 +642,12 @@ export default class Model implements TableType {
}
// delete alias cache
await NocoCache.del(
`${CacheScope.MODEL}:${oldModel.base_id}:${oldModel.source_id}:${oldModel.title}`,
);
await NocoCache.del(
`${CacheScope.MODEL}:${oldModel.base_id}:${oldModel.title}`,
);
await NocoCache.del([
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.id}`,
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.source_id}:${oldModel.id}`,
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.title}`,
`${CacheScope.MODEL_ALIAS}:${oldModel.base_id}:${oldModel.source_id}:${oldModel.title}`,
]);
// set meta
const res = await ncMeta.metaUpdate(

13
packages/nocodb/src/models/ModelRoleVisibility.ts

@ -114,12 +114,7 @@ export default class ModelRoleVisibility implements ModelRoleVisibilityType {
return await ModelRoleVisibility.delete(this.fk_view_id, this.role);
}
static async delete(fk_view_id: string, role: string) {
await NocoCache.deepDel(
CacheScope.MODEL_ROLE_VISIBILITY,
`${CacheScope.MODEL_ROLE_VISIBILITY}:${fk_view_id}:${role}`,
CacheDelDirection.CHILD_TO_PARENT,
);
return await Noco.ncMeta.metaDelete(
const res = await Noco.ncMeta.metaDelete(
null,
null,
MetaTable.MODEL_ROLE_VISIBILITY,
@ -128,6 +123,12 @@ export default class ModelRoleVisibility implements ModelRoleVisibilityType {
role,
},
);
await NocoCache.deepDel(
CacheScope.MODEL_ROLE_VISIBILITY,
`${CacheScope.MODEL_ROLE_VISIBILITY}:${fk_view_id}:${role}`,
CacheDelDirection.CHILD_TO_PARENT,
);
return res;
}
static async insert(

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

@ -183,12 +183,14 @@ export default class Sort {
public static async delete(sortId: string, ncMeta = Noco.ncMeta) {
const sort = await this.get(sortId, ncMeta);
await ncMeta.metaDelete(null, null, MetaTable.SORT, sortId);
await NocoCache.deepDel(
CacheScope.SORT,
`${CacheScope.SORT}:${sortId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
await ncMeta.metaDelete(null, null, MetaTable.SORT, sortId);
// on delete, delete any optimised single query cache
if (sort?.fk_view_id) {

17
packages/nocodb/src/models/Source.ts

@ -423,11 +423,6 @@ export default class Source implements SourceType {
for (const model of models) {
await model.delete(ncMeta, true);
}
await NocoCache.deepDel(
CacheScope.BASE,
`${CacheScope.BASE}:${this.id}`,
CacheDelDirection.CHILD_TO_PARENT,
);
const syncSources = await SyncSource.list(this.base_id, this.id, ncMeta);
for (const syncSource of syncSources) {
@ -436,7 +431,15 @@ export default class Source implements SourceType {
await NcConnectionMgrv2.deleteAwait(this);
return await ncMeta.metaDelete(null, null, MetaTable.BASES, this.id);
const res = await ncMeta.metaDelete(null, null, MetaTable.BASES, this.id);
await NocoCache.deepDel(
CacheScope.BASE,
`${CacheScope.BASE}:${this.id}`,
CacheDelDirection.CHILD_TO_PARENT,
);
return res;
}
async softDelete(ncMeta = Noco.ncMeta, { force }: { force?: boolean } = {}) {
@ -461,8 +464,6 @@ export default class Source implements SourceType {
`${CacheScope.BASE}:${this.id}`,
CacheDelDirection.CHILD_TO_PARENT,
);
await NocoCache.del(`${CacheScope.BASE}:${this.id}`);
}
async getModels(ncMeta = Noco.ncMeta) {

14
packages/nocodb/src/models/View.ts

@ -1106,27 +1106,29 @@ export default class View implements ViewType {
await ncMeta.metaDelete(null, null, columnTable, {
fk_view_id: viewId,
});
await ncMeta.metaDelete(null, null, table, {
fk_view_id: viewId,
});
await ncMeta.metaDelete(null, null, MetaTable.VIEWS, viewId);
await NocoCache.deepDel(
tableScope,
`${tableScope}:${viewId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
await ncMeta.metaDelete(null, null, table, {
fk_view_id: viewId,
});
await NocoCache.deepDel(
columnTableScope,
`${columnTableScope}:${viewId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
await ncMeta.metaDelete(null, null, MetaTable.VIEWS, viewId);
await NocoCache.deepDel(
CacheScope.VIEW,
`${CacheScope.VIEW}:${viewId}`,
CacheDelDirection.CHILD_TO_PARENT,
);
await NocoCache.del(`${CacheScope.VIEW}:${view.fk_model_id}:${view.title}`);
await NocoCache.del(`${CacheScope.VIEW}:${view.fk_model_id}:${view.id}`);
await NocoCache.del([
`${CacheScope.VIEW_ALIAS}:${view.fk_model_id}:${view.title}`,
`${CacheScope.VIEW_ALIAS}:${view.fk_model_id}:${view.id}`,
]);
// on update, delete any optimised single query cache
await View.clearSingleQueryCache(view.fk_model_id, [view]);

Loading…
Cancel
Save