From 4bda0046136fc99498a7a80ef37e4e083d3dc55e Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 16 Apr 2024 07:14:20 +0000 Subject: [PATCH] refactor: update cache only after metadb change --- .../nocodb/src/models/GalleryViewColumn.ts | 19 ++++++++------- .../nocodb/src/models/KanbanViewColumn.ts | 23 +++++++++---------- packages/nocodb/src/models/MapViewColumn.ts | 18 ++++++++------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/packages/nocodb/src/models/GalleryViewColumn.ts b/packages/nocodb/src/models/GalleryViewColumn.ts index cefaa10132..5a4a36fe4b 100644 --- a/packages/nocodb/src/models/GalleryViewColumn.ts +++ b/packages/nocodb/src/models/GalleryViewColumn.ts @@ -128,23 +128,26 @@ export default class GalleryViewColumn { ncMeta = Noco.ncMeta, ) { const updateObj = extractProps(body, ['order', 'show']); + + // set meta + const res = await ncMeta.metaUpdate( + null, + null, + MetaTable.GALLERY_VIEW_COLUMNS, + updateObj, + columnId, + ); + // get existing cache const key = `${CacheScope.GALLERY_VIEW_COLUMN}:${columnId}`; let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); + if (o) { // update data o = { ...o, ...updateObj }; // set cache await NocoCache.set(key, o); } - // set meta - const res = await ncMeta.metaUpdate( - null, - null, - MetaTable.GALLERY_VIEW_COLUMNS, - updateObj, - columnId, - ); // on view column update, delete any optimised single query cache { diff --git a/packages/nocodb/src/models/KanbanViewColumn.ts b/packages/nocodb/src/models/KanbanViewColumn.ts index c739a74462..468bf1cf74 100644 --- a/packages/nocodb/src/models/KanbanViewColumn.ts +++ b/packages/nocodb/src/models/KanbanViewColumn.ts @@ -119,10 +119,17 @@ export default class KanbanViewColumn implements KanbanColumnType { body: Partial, ncMeta = Noco.ncMeta, ) { - const updateObj = extractProps(body, [ - 'order', - 'show' - ]); + const updateObj = extractProps(body, ['order', 'show']); + + // set meta + const res = await ncMeta.metaUpdate( + null, + null, + MetaTable.KANBAN_VIEW_COLUMNS, + updateObj, + columnId, + ); + // get existing cache const key = `${CacheScope.KANBAN_VIEW_COLUMN}:${columnId}`; let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); @@ -132,14 +139,6 @@ export default class KanbanViewColumn implements KanbanColumnType { // set cache await NocoCache.set(key, o); } - // set meta - const res = await ncMeta.metaUpdate( - null, - null, - MetaTable.KANBAN_VIEW_COLUMNS, - updateObj, - columnId, - ); // on view column update, delete any optimised single query cache { diff --git a/packages/nocodb/src/models/MapViewColumn.ts b/packages/nocodb/src/models/MapViewColumn.ts index 4eb2786e33..04631643c3 100644 --- a/packages/nocodb/src/models/MapViewColumn.ts +++ b/packages/nocodb/src/models/MapViewColumn.ts @@ -117,6 +117,16 @@ export default class MapViewColumn { 'group_by_order', 'group_by_sort', ]); + + // set meta + const res = await ncMeta.metaUpdate( + null, + null, + MetaTable.MAP_VIEW_COLUMNS, + updateObj, + columnId, + ); + // get existing cache const key = `${CacheScope.MAP_VIEW_COLUMN}:${columnId}`; let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); @@ -126,14 +136,6 @@ export default class MapViewColumn { // set cache await NocoCache.set(key, o); } - // set meta - const res = await ncMeta.metaUpdate( - null, - null, - MetaTable.MAP_VIEW_COLUMNS, - updateObj, - columnId, - ); // on view column update, delete any optimised single query cache {