From 75c676b5cad5cb0b96048d09665ab36c75253d90 Mon Sep 17 00:00:00 2001 From: montaghanmy Date: Wed, 20 Sep 2023 22:36:31 +0100 Subject: [PATCH] fix: updated query builder --- .../services/orm/connectors/cassandra/query-builder.ts | 5 ++++- .../node/src/services/documents/entities/drive-file.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/cassandra/query-builder.ts b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/cassandra/query-builder.ts index 63c05ad39..61a632a4d 100644 --- a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/cassandra/query-builder.ts +++ b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/cassandra/query-builder.ts @@ -18,6 +18,7 @@ export function buildSelectQuery( ): string { const instance = new (entityType as any)(); const { columnsDefinition, entityDefinition } = getEntityDefinition(instance); + let allowFiltering = false; const where = Object.keys(filters) .map(key => { @@ -28,6 +29,7 @@ export function buildSelectQuery( return; } if (isObject(filter) && JSON.stringify(filter).includes("ne")) { + allowFiltering = true; result = `${key} IN (NULL, false)`; return result; } @@ -47,6 +49,7 @@ export function buildSelectQuery( result = `${key} IN (${inClause.join(",")})`; } else { + if (key === "is_in_trash" || key === "scope") allowFiltering = true; result = `${key} = ${transformValueToDbString(filter, columnsDefinition[key].type, { columns: columnsDefinition[key].options, secret: options.secret || "", @@ -82,7 +85,7 @@ export function buildSelectQuery( whereClause.trim().length ? "WHERE " + whereClause : "" } ${orderByClause.trim().length ? "ORDER BY " + orderByClause : ""}` .trimEnd() - .concat(";"); + .concat(allowFiltering ? " ALLOW FILTERING;" : ";"); return query; } diff --git a/tdrive/backend/node/src/services/documents/entities/drive-file.ts b/tdrive/backend/node/src/services/documents/entities/drive-file.ts index 0ad29808f..00aaa704c 100644 --- a/tdrive/backend/node/src/services/documents/entities/drive-file.ts +++ b/tdrive/backend/node/src/services/documents/entities/drive-file.ts @@ -9,7 +9,7 @@ export type DriveScope = "personal" | "shared"; @Entity(TYPE, { globalIndexes: [["company_id", "parent_id"]], - primaryKey: [["company_id"], "is_in_trash", "scope", "id"], + primaryKey: [["company_id"], "id"], type: TYPE, search, })