From 68e83c8c519b858609ffad906e9bd74d2abb7d48 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 3 Apr 2024 19:09:33 +0000 Subject: [PATCH] fix: clear view column cache properly when deleting column --- .../nocodb/src/models/CalendarViewColumn.ts | 7 +- packages/nocodb/src/models/Column.ts | 76 ++++++++++++------- packages/nocodb/src/models/FormViewColumn.ts | 4 +- .../nocodb/src/models/GalleryViewColumn.ts | 7 +- packages/nocodb/src/models/GridViewColumn.ts | 2 - .../nocodb/src/models/KanbanViewColumn.ts | 4 +- packages/nocodb/src/models/MapViewColumn.ts | 4 +- 7 files changed, 53 insertions(+), 51 deletions(-) diff --git a/packages/nocodb/src/models/CalendarViewColumn.ts b/packages/nocodb/src/models/CalendarViewColumn.ts index 2aa263900e..0fc4e49440 100644 --- a/packages/nocodb/src/models/CalendarViewColumn.ts +++ b/packages/nocodb/src/models/CalendarViewColumn.ts @@ -79,18 +79,13 @@ export default class CalendarViewColumn { insertObj.source_id = viewRef.source_id; } - const { id, fk_column_id } = await ncMeta.metaInsert2( + const { id } = await ncMeta.metaInsert2( null, null, MetaTable.CALENDAR_VIEW_COLUMNS, insertObj, ); - await NocoCache.set( - `${CacheScope.CALENDAR_VIEW_COLUMN}:${fk_column_id}`, - id, - ); - { const view = await View.get(column.fk_view_id, ncMeta); await View.clearSingleQueryCache(view.fk_model_id, [view], ncMeta); diff --git a/packages/nocodb/src/models/Column.ts b/packages/nocodb/src/models/Column.ts index d89a7aea41..2ad40a16b7 100644 --- a/packages/nocodb/src/models/Column.ts +++ b/packages/nocodb/src/models/Column.ts @@ -824,61 +824,81 @@ export default class Column implements ColumnType { } // Grid View Columns + const gridViewColumns = await ncMeta.metaList2( + null, + null, + MetaTable.GRID_VIEW_COLUMNS, + { + condition: { fk_column_id: id }, + }, + ); await ncMeta.metaDelete(null, null, MetaTable.GRID_VIEW_COLUMNS, { - fk_column_id: col.id, + fk_column_id: id, }); - const gridViewColumnId = await NocoCache.get( - `${CacheScope.GRID_VIEW_COLUMN}:${col.id}`, - CacheGetType.TYPE_STRING, - ); - if (gridViewColumnId) { + + for (const gridViewColumn of gridViewColumns) { await NocoCache.deepDel( - `${CacheScope.GRID_VIEW_COLUMN}:${gridViewColumnId}`, + `${CacheScope.GRID_VIEW_COLUMN}:${gridViewColumn.id}`, CacheDelDirection.CHILD_TO_PARENT, ); } // Form View Columns + const formViewColumns = await ncMeta.metaList2( + null, + null, + MetaTable.FORM_VIEW_COLUMNS, + { + condition: { fk_column_id: id }, + }, + ); await ncMeta.metaDelete(null, null, MetaTable.FORM_VIEW_COLUMNS, { - fk_column_id: col.id, + fk_column_id: id, }); - const formViewColumnId = await NocoCache.get( - `${CacheScope.FORM_VIEW_COLUMN}:${col.id}`, - CacheGetType.TYPE_STRING, - ); - if (formViewColumnId) { + + for (const formViewColumn of formViewColumns) { await NocoCache.deepDel( - `${CacheScope.FORM_VIEW_COLUMN}:${formViewColumnId}`, + `${CacheScope.FORM_VIEW_COLUMN}:${formViewColumn.id}`, CacheDelDirection.CHILD_TO_PARENT, ); } // Kanban View Columns + const kanbanViewColumns = await ncMeta.metaList2( + null, + null, + MetaTable.KANBAN_VIEW_COLUMNS, + { + condition: { fk_column_id: id }, + }, + ); await ncMeta.metaDelete(null, null, MetaTable.KANBAN_VIEW_COLUMNS, { - fk_column_id: col.id, + fk_column_id: id, }); - const kanbanViewColumnId = await NocoCache.get( - `${CacheScope.KANBAN_VIEW_COLUMN}:${col.id}`, - CacheGetType.TYPE_STRING, - ); - if (kanbanViewColumnId) { + + for (const kanbanViewColumn of kanbanViewColumns) { await NocoCache.deepDel( - `${CacheScope.KANBAN_VIEW_COLUMN}:${kanbanViewColumnId}`, + `${CacheScope.KANBAN_VIEW_COLUMN}:${kanbanViewColumn.id}`, CacheDelDirection.CHILD_TO_PARENT, ); } // Gallery View Column + const galleryViewColumns = await ncMeta.metaList2( + null, + null, + MetaTable.GALLERY_VIEW_COLUMNS, + { + condition: { fk_column_id: id }, + }, + ); await ncMeta.metaDelete(null, null, MetaTable.GALLERY_VIEW_COLUMNS, { - fk_column_id: col.id, + fk_column_id: id, }); - const galleryViewColumnId = await NocoCache.get( - `${CacheScope.GALLERY_VIEW_COLUMN}:${col.id}`, - CacheGetType.TYPE_STRING, - ); - if (galleryViewColumnId) { + + for (const galleryViewColumn of galleryViewColumns) { await NocoCache.deepDel( - `${CacheScope.GALLERY_VIEW_COLUMN}:${galleryViewColumnId}`, + `${CacheScope.GALLERY_VIEW_COLUMN}:${galleryViewColumn.id}`, CacheDelDirection.CHILD_TO_PARENT, ); } diff --git a/packages/nocodb/src/models/FormViewColumn.ts b/packages/nocodb/src/models/FormViewColumn.ts index 518b3cc2dc..5265dbc794 100644 --- a/packages/nocodb/src/models/FormViewColumn.ts +++ b/packages/nocodb/src/models/FormViewColumn.ts @@ -92,15 +92,13 @@ export default class FormViewColumn implements FormColumnType { insertObj.source_id = viewRef.source_id; } - const { id, fk_column_id } = await ncMeta.metaInsert2( + const { id } = await ncMeta.metaInsert2( null, null, MetaTable.FORM_VIEW_COLUMNS, insertObj, ); - await NocoCache.set(`${CacheScope.FORM_VIEW_COLUMN}:${fk_column_id}`, id); - return this.get(id, ncMeta).then(async (viewColumn) => { await NocoCache.appendToList( CacheScope.FORM_VIEW_COLUMN, diff --git a/packages/nocodb/src/models/GalleryViewColumn.ts b/packages/nocodb/src/models/GalleryViewColumn.ts index c893b7aa30..6ea557ef75 100644 --- a/packages/nocodb/src/models/GalleryViewColumn.ts +++ b/packages/nocodb/src/models/GalleryViewColumn.ts @@ -66,18 +66,13 @@ export default class GalleryViewColumn { insertObj.source_id = viewRef.source_id; } - const { id, fk_column_id } = await ncMeta.metaInsert2( + const { id } = await ncMeta.metaInsert2( null, null, MetaTable.GALLERY_VIEW_COLUMNS, insertObj, ); - await NocoCache.set( - `${CacheScope.GALLERY_VIEW_COLUMN}:${fk_column_id}`, - id, - ); - // on new view column, delete any optimised single query cache { const view = await View.get(column.fk_view_id, ncMeta); diff --git a/packages/nocodb/src/models/GridViewColumn.ts b/packages/nocodb/src/models/GridViewColumn.ts index e5ab0fbdf9..b0eb14ed42 100644 --- a/packages/nocodb/src/models/GridViewColumn.ts +++ b/packages/nocodb/src/models/GridViewColumn.ts @@ -107,8 +107,6 @@ export default class GridViewColumn implements GridColumnType { insertObj, ); - await NocoCache.set(`${CacheScope.GRID_VIEW_COLUMN}:${fk_column_id}`, id); - await View.fixPVColumnForView(column.fk_view_id, ncMeta); // on new view column, delete any optimised single query cache diff --git a/packages/nocodb/src/models/KanbanViewColumn.ts b/packages/nocodb/src/models/KanbanViewColumn.ts index abb723979d..dca4b4b1f3 100644 --- a/packages/nocodb/src/models/KanbanViewColumn.ts +++ b/packages/nocodb/src/models/KanbanViewColumn.ts @@ -63,15 +63,13 @@ export default class KanbanViewColumn implements KanbanColumnType { insertObj.source_id = viewRef.source_id; } - const { id, fk_column_id } = await ncMeta.metaInsert2( + const { id } = await ncMeta.metaInsert2( null, null, MetaTable.KANBAN_VIEW_COLUMNS, insertObj, ); - await NocoCache.set(`${CacheScope.KANBAN_VIEW_COLUMN}:${fk_column_id}`, id); - return this.get(id, ncMeta).then(async (kanbanViewColumn) => { await NocoCache.appendToList( CacheScope.KANBAN_VIEW_COLUMN, diff --git a/packages/nocodb/src/models/MapViewColumn.ts b/packages/nocodb/src/models/MapViewColumn.ts index 6ecfdc38ab..e482b6ba4f 100644 --- a/packages/nocodb/src/models/MapViewColumn.ts +++ b/packages/nocodb/src/models/MapViewColumn.ts @@ -57,15 +57,13 @@ export default class MapViewColumn { insertObj.source_id = viewRef.source_id; } - const { id, fk_column_id } = await ncMeta.metaInsert2( + const { id } = await ncMeta.metaInsert2( null, null, MetaTable.MAP_VIEW_COLUMNS, insertObj, ); - await NocoCache.set(`${CacheScope.MAP_VIEW_COLUMN}:${fk_column_id}`, id); - return this.get(id, ncMeta).then(async (viewCol) => { await NocoCache.appendToList( CacheScope.MAP_VIEW_COLUMN,