From 0d08ade2011b653c466fae8efa98179c0572d6d0 Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Tue, 20 Feb 2024 07:16:05 +0000 Subject: [PATCH] fix(nocodb): update cache clear logic --- packages/nocodb/src/models/CalendarRange.ts | 25 ++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/nocodb/src/models/CalendarRange.ts b/packages/nocodb/src/models/CalendarRange.ts index 8539c9b514..eb4386bff3 100644 --- a/packages/nocodb/src/models/CalendarRange.ts +++ b/packages/nocodb/src/models/CalendarRange.ts @@ -2,7 +2,12 @@ import type { CalendarRangeType } from 'nocodb-sdk'; import Noco from '~/Noco'; import NocoCache from '~/cache/NocoCache'; import { extractProps } from '~/helpers/extractProps'; -import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals'; +import { + CacheDelDirection, + CacheGetType, + CacheScope, + MetaTable, +} from '~/utils/globals'; export default class CalendarRange implements CalendarRangeType { id?: string; @@ -61,19 +66,29 @@ export default class CalendarRange implements CalendarRangeType { MetaTable.CALENDAR_VIEW_RANGE, insertObj, ); - // clear cache - const uniqueFks = [...new Set(bulkData.map((d) => d.fk_view_id))]; + const uniqueFks: string[] = [ + ...new Set(bulkData.map((d) => d.fk_view_id)), + ] as string[]; + for (const fk of uniqueFks) { - await NocoCache.delAll(CacheScope.CALENDAR_VIEW_RANGE, `${fk}:*`); + await NocoCache.deepDel( + CacheScope.CALENDAR_VIEW_RANGE, + fk, + CacheDelDirection.PARENT_TO_CHILD, + ); } for (const d of bulkData) { + await NocoCache.set( + `${CacheScope.CALENDAR_VIEW_RANGE}:${d.fk_view_id}`, + d, + ); + await NocoCache.appendToList( CacheScope.CALENDAR_VIEW_RANGE, [d.fk_view_id], `${CacheScope.CALENDAR_VIEW_RANGE}:${d.id}`, ); - await NocoCache.set(`${CacheScope.CALENDAR_VIEW_RANGE}:${d.id}`, d); } return true;