Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix filter cache

Fendy Heryantodc47761dc640
diff --git a/packages/nocodb/src/services/v3/filters-v3.service.ts b/packages/nocodb/src/services/v3/filters-v3.service.ts
index 99545f1d2d..dd82a5fdec 100644
--- a/packages/nocodb/src/services/v3/filters-v3.service.ts
+++ b/packages/nocodb/src/services/v3/filters-v3.service.ts
@@ -1,7 +1,6 @@
import { Injectable } from '@nestjs/common';
import type {
FilterCreateV3Type,
- FilterGroupLevel3V3Type,
FilterGroupV3Type,
FilterReqType,
FilterType,
@@ -12,17 +11,18 @@ import type {
import type { NcContext, NcRequest } from '~/interface/config';
import type { MetaService } from '~/meta/meta.service';
import type { ViewWebhookManager } from '~/utils/view-webhook-manager';
-import { ViewWebhookManagerBuilder } from '~/utils/view-webhook-manager';
-import RowColorCondition from '~/models/RowColorCondition';
-import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
+import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError';
import { Filter, Hook, View } from '~/models';
+import RowColorCondition from '~/models/RowColorCondition';
+import Noco from '~/Noco';
+import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
+import { FiltersService } from '~/services/filters.service';
import {
filterBuilder,
filterRevBuilder,
} from '~/utils/api-v3-data-transformation.builder';
-import { FiltersService } from '~/services/filters.service';
-import { validatePayload } from '~/helpers';
+import { ViewWebhookManagerBuilder } from '~/utils/view-webhook-manager';
function extractLogicalOp(group_operator: 'AND' | 'OR') {
return group_operator?.toLowerCase() as 'and' | 'or';
@@ -131,7 +131,7 @@ export class FiltersV3Service {
isRoot = true, // Flag to check if it's the root group
viewId,
viewWebhookManager,
- ncMeta,
+ ncMeta = Noco.ncMeta,
}: {
context: any;
param:
@@ -161,7 +161,6 @@ export class FiltersV3Service {
ncMeta,
);
let innerViewWebhookManager: ViewWebhookManager;
-
if ((param as any).viewId && !viewWebhookManager) {
const view = await View.get(context, (param as any).viewId, ncMeta);
innerViewWebhookManager = (param as any).viewId
@@ -173,7 +172,7 @@ export class FiltersV3Service {
).withViewId(view.id)
).forUpdate()
: null;
- } else if ((param as any).rowColorConditionId) {
+ } else if ((param as any).rowColorConditionId && !viewWebhookManager) {
const rowColorCondition = await RowColorCondition.getById(
context,
(param as any).rowColorConditionId,
@@ -197,11 +196,15 @@ export class FiltersV3Service {
if (!logicalOp) {
logicalOp =
(
- await this.extractGroup(context, {
- viewId: viewId,
- parentFilterId:
- parentId || (groupOrFilter as any)?.parent_id || 'root',
- })
+ await this.extractGroup(
+ context,
+ {
+ viewId: viewId,
+ parentFilterId:
+ parentId || (groupOrFilter as any)?.parent_id || 'root',
+ },
+ ncMeta,
+ )
)?.group_operator || 'AND';
}
@@ -263,6 +266,7 @@ export class FiltersV3Service {
fk_parent_id: null, // Root groups have no parent
logical_op: extractLogicalOp(logicalOp),
...additionalProps,
+ id: undefined,
},
ncMeta,
);
@@ -279,6 +283,7 @@ export class FiltersV3Service {
fk_parent_id: parentId, // Root groups have no parent
logical_op: extractLogicalOp(logicalOp),
...additionalProps,
+ id: undefined,
},
ncMeta,
);
@@ -312,6 +317,7 @@ export class FiltersV3Service {
logicalOp: groupOrFilter.group_operator, // Pass the current group's logical operator
isRoot: false, // Indicate it's not the root
viewId,
+ ncMeta,
});
}
}
@@ -324,6 +330,7 @@ export class FiltersV3Service {
fk_parent_id: currentParentId, // Link to the parent group or root
logical_op: extractLogicalOp(logicalOp), // Pass the logical operator
...additionalProps,
+ id: undefined,
},
ncMeta,
);
@@ -489,11 +496,16 @@ export class FiltersV3Service {
viewId: string;
parentFilterId: string;
},
+ ncMeta = Noco.ncMeta,
) {
// get nested list
- const list = await this.filterList(context, {
- viewId: param.viewId,
- });
+ const list = await this.filterList(
+ context,
+ {
+ viewId: param.viewId,
+ },
+ ncMeta,
+ );
if (param.parentFilterId === 'root') {
return list;
@@ -519,21 +531,34 @@ export class FiltersV3Service {
async filterList(
context: NcContext,
param: { viewId: string } | { hookId: string } | { linkColumnId: string },
+ ncMeta = Noco.ncMeta,
) {
let filters = [];
if ('hookId' in param && param.hookId) {
- filters = await Filter.allHookFilterList(context, {
- hookId: param.hookId,
- });
+ filters = await Filter.allHookFilterList(
+ context,
+ {
+ hookId: param.hookId,
+ },
+ ncMeta,
+ );
} else if ('linkColumnId' in param && param.linkColumnId) {
- filters = await Filter.allLinkFilterList(context, {
- linkColumnId: param.linkColumnId,
- });
+ filters = await Filter.allLinkFilterList(
+ context,
+ {
+ linkColumnId: param.linkColumnId,
+ },
+ ncMeta,
+ );
} else if ('viewId' in param && param.viewId) {
- filters = await Filter.allViewFilterList(context, {
- viewId: param.viewId,
- });
+ filters = await Filter.allViewFilterList(
+ context,
+ {
+ viewId: param.viewId,
+ },
+ ncMeta,
+ );
}
return addDummyRootAndNest(filterBuilder().build(filters) as Filter[]);
@@ -573,22 +598,4 @@ export class FiltersV3Service {
) {
return Filter.deleteAll(context, param.viewId, ncMeta);
}
-
- withoutId(
- filters: (FilterV3Type | (FilterGroupLevel3V3Type & { id?: string }))[],
- ) {
- if (!filters || !filters.length) {
- return [];
- }
- return filters.map((flt) => {
- const { id, ...rest } = flt;
- if ('filters' in rest) {
- return {
- ...rest,
- filters: this.withoutId(rest.filters),
- };
- }
- return rest;
- });
- }
}
diff --git a/packages/nocodb/src/utils/view-webhook-manager.ts b/packages/nocodb/src/utils/view-webhook-manager.ts
index 8b12a840e8..838f407414 100644
--- a/packages/nocodb/src/utils/view-webhook-manager.ts
+++ b/packages/nocodb/src/utils/view-webhook-manager.ts
@@ -51,11 +51,15 @@ export class ViewWebhookManagerBuilder {
`Need to call 'withModel' before running 'forCreate'`,
);
}
- return new ViewWebhookManager(this.context, {
- action: WebhookActions.INSERT,
- modelId: this.modelId!,
- modelWebhookManager: this.modelWebhookManager,
- });
+ return new ViewWebhookManager(
+ this.context,
+ {
+ action: WebhookActions.INSERT,
+ modelId: this.modelId!,
+ modelWebhookManager: this.modelWebhookManager,
+ },
+ this.ncMeta,
+ );
}
forUpdate() {
@@ -64,12 +68,16 @@ export class ViewWebhookManagerBuilder {
`Need to call 'withModel' before running 'forUpdate'`,
);
}
- return new ViewWebhookManager(this.context, {
- action: WebhookActions.UPDATE,
- modelId: this.modelId!,
- oldView: this.oldView,
- modelWebhookManager: this.modelWebhookManager,
- });
+ return new ViewWebhookManager(
+ this.context,
+ {
+ action: WebhookActions.UPDATE,
+ modelId: this.modelId!,
+ oldView: this.oldView,
+ modelWebhookManager: this.modelWebhookManager,
+ },
+ this.ncMeta,
+ );
}
forDelete() {