From b82b78aa7d6198608c57de208113320684306073 Mon Sep 17 00:00:00 2001 From: Anton Shepilov Date: Tue, 27 Feb 2024 15:31:11 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8FSpeed=20up=20"shared=20wit?= =?UTF-8?q?h=20me"=20query=20(#381)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .run/Run all e2e [MongoDB].run.xml | 2 +- .../services/orm/connectors/mongodb/query-builder.ts | 12 ++++++++++++ .../database/services/orm/repository/repository.ts | 1 + .../node/src/core/platform/services/storage/index.ts | 4 ++-- .../node/src/services/documents/services/index.ts | 1 + .../test/e2e/documents/documents-browser.spec.ts | 4 ++-- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.run/Run all e2e [MongoDB].run.xml b/.run/Run all e2e [MongoDB].run.xml index 359d59bc..8464490f 100644 --- a/.run/Run all e2e [MongoDB].run.xml +++ b/.run/Run all e2e [MongoDB].run.xml @@ -9,7 +9,7 @@ - + diff --git a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/mongodb/query-builder.ts b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/mongodb/query-builder.ts index 5efa386c..6a50c1a1 100644 --- a/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/mongodb/query-builder.ts +++ b/tdrive/backend/node/src/core/platform/services/database/services/orm/connectors/mongodb/query-builder.ts @@ -40,6 +40,7 @@ export function buildSelectQuery( findOptions = secureOperators(transformValueToDbString, findOptions, entityType, options); where = buildComparison(where, findOptions); where = buildIn(where, findOptions); + where = buildNin(where, findOptions); return where; } @@ -67,3 +68,14 @@ export function buildIn(where: any, options: FindOptions = {}): any { return where; } + +export function buildNin(where: any, options: FindOptions = {}): any { + if (options.$nin) { + options.$nin.forEach(element => { + if (!where[element[0]]) where[element[0]] = {}; + where[element[0]]["$nin"] = element[1]; + }); + } + + return where; +} diff --git a/tdrive/backend/node/src/core/platform/services/database/services/orm/repository/repository.ts b/tdrive/backend/node/src/core/platform/services/database/services/orm/repository/repository.ts index 2d6f64c1..a180a92b 100644 --- a/tdrive/backend/node/src/core/platform/services/database/services/orm/repository/repository.ts +++ b/tdrive/backend/node/src/core/platform/services/database/services/orm/repository/repository.ts @@ -32,6 +32,7 @@ export type FindOptions = { * The $in operator selects the documents where the value of a field equals any value in the specified array */ $in?: inType[]; + $nin?: inType[]; $like?: likeType[]; }; diff --git a/tdrive/backend/node/src/core/platform/services/storage/index.ts b/tdrive/backend/node/src/core/platform/services/storage/index.ts index e03e69fb..a92a0efe 100644 --- a/tdrive/backend/node/src/core/platform/services/storage/index.ts +++ b/tdrive/backend/node/src/core/platform/services/storage/index.ts @@ -58,8 +58,8 @@ export default class StorageService extends TdriveService implements }); } else { logger.info("Using 'local' connector for storage."); - const defaultHomeDir = this.configuration.get("local.path"); - if (defaultHomeDir) this.homeDir = `${defaultHomeDir}`; + // const defaultHomeDir = this.configuration.get("local.path"); + // if (defaultHomeDir) this.homeDir = `${defaultHomeDir}`; logger.trace(`Home directory for the storage: ${this.homeDir}`); } logger.info( diff --git a/tdrive/backend/node/src/services/documents/services/index.ts b/tdrive/backend/node/src/services/documents/services/index.ts index a3244621..0b94c56a 100644 --- a/tdrive/backend/node/src/services/documents/services/index.ts +++ b/tdrive/backend/node/src/services/documents/services/index.ts @@ -986,6 +986,7 @@ export class DocumentsService { ] : []), ], + $nin: [...(options.onlyDirectlyShared ? [["creator", [context.user.id]] as inType] : [])], $lte: [ ...(options.last_modified_lt ? [["last_modified", options.last_modified_lt] as comparisonType] diff --git a/tdrive/backend/node/test/e2e/documents/documents-browser.spec.ts b/tdrive/backend/node/test/e2e/documents/documents-browser.spec.ts index 2742f23a..3b65c6dd 100644 --- a/tdrive/backend/node/test/e2e/documents/documents-browser.spec.ts +++ b/tdrive/backend/node/test/e2e/documents/documents-browser.spec.ts @@ -89,7 +89,7 @@ describe("The Documents Browser Window and API", () => { }); describe("Shared With Me", () => { - it("Shouldn't contain files uploaded to the user folder", async () => { + it("Shouldn't contain user personal files", async () => { const sharedWIthMeFolder = "shared_with_me"; await currentUser.uploadAllFilesOneByOne("user_" + currentUser.user.id); await new Promise(r => setTimeout(r, 5000)); @@ -129,7 +129,7 @@ describe("The Documents Browser Window and API", () => { expect((await anotherUser.browseDocuments("shared_with_me", {pageSize: 1})).children).toHaveLength(1); }); - it("Share With Me should return all the files that was share by user at one", async () => { + it("Should return ALL the files that was share by user at one", async () => { const sharedWIthMeFolder = "shared_with_me"; const oneUser = await UserApi.getInstance(platform, true, {companyRole: "admin"}); const anotherUser = await UserApi.getInstance(platform, true, {companyRole: "admin"});