From 956544293e58f569e23ca2aba676725b8cfce433 Mon Sep 17 00:00:00 2001 From: montaghanmy Date: Thu, 21 Sep 2023 10:03:34 +0100 Subject: [PATCH] feat: added is_in_trash index + ref --- .../orm/connectors/cassandra/query-builder.ts | 13 +++++-------- .../services/database/services/orm/utils.ts | 9 +++++++++ .../src/services/documents/entities/drive-file.ts | 5 ++++- 3 files changed, 18 insertions(+), 9 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 61a632a4d..5b8d28b3e 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 @@ -1,7 +1,6 @@ -import { isObject } from "lodash"; import { FindOptions } from "../../repository/repository"; import { ObjectType } from "../../types"; -import { getEntityDefinition, secureOperators } from "../../utils"; +import { getEntityDefinition, secureOperators, filteringRequired } from "../../utils"; import { transformValueToDbString } from "./typeTransforms"; export function buildSelectQuery( @@ -25,14 +24,13 @@ export function buildSelectQuery( let result: string; const filter = filters[key]; + if (filteringRequired(key)) { + allowFiltering = true; + } + if (!filter) { return; } - if (isObject(filter) && JSON.stringify(filter).includes("ne")) { - allowFiltering = true; - result = `${key} IN (NULL, false)`; - return result; - } if (Array.isArray(filter)) { if (!filter.length) { @@ -49,7 +47,6 @@ 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 || "", diff --git a/tdrive/backend/node/src/core/platform/services/database/services/orm/utils.ts b/tdrive/backend/node/src/core/platform/services/database/services/orm/utils.ts index 91abd3690..22f51b941 100644 --- a/tdrive/backend/node/src/core/platform/services/database/services/orm/utils.ts +++ b/tdrive/backend/node/src/core/platform/services/database/services/orm/utils.ts @@ -106,3 +106,12 @@ export function toMongoDbOrderable(timeuuid?: string): string { const time_str = [uuid_arr[2], uuid_arr[1], uuid_arr[0], uuid_arr[3], uuid_arr[4]].join("-"); return time_str; } + +/** + * Check if filtering is necessary + * @param {string} key + * @returns {boolean} Returns true if key is "is_in_trash" or "scope", otherwise returns false. + */ +export const filteringRequired = (key: string) => { + return key === "is_in_trash" || key === "scope"; +}; 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 00aaa704c..6b96f567f 100644 --- a/tdrive/backend/node/src/services/documents/entities/drive-file.ts +++ b/tdrive/backend/node/src/services/documents/entities/drive-file.ts @@ -8,7 +8,10 @@ export const TYPE = "drive_files"; export type DriveScope = "personal" | "shared"; @Entity(TYPE, { - globalIndexes: [["company_id", "parent_id"]], + globalIndexes: [ + ["company_id", "parent_id"], + ["company_id", "is_in_trash"], + ], primaryKey: [["company_id"], "id"], type: TYPE, search,