Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🛠️ Speed up "shared with me" query #381

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .run/Run all e2e [MongoDB].run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<env name="DB_MONGO_URI" value="mongodb://localhost:27017" />
<env name="PUBSUB_TYPE" value="local" />
<env name="SEARCH_DRIVER" value="mongodb" />
<env name="STORAGE_LOCAL_PATH" value="$USER_HOME$/dev/linagora/TDrive/tdrive/docker-data" />
<env name="STORAGE_LOCAL_PATH" value="/tmp" />
</envs>
<scope-kind value="DIRECTORY" />
<test-directory value="$PROJECT_DIR$/tdrive/backend/node/test/e2e" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function buildSelectQuery<Entity>(
findOptions = secureOperators(transformValueToDbString, findOptions, entityType, options);
where = buildComparison(where, findOptions);
where = buildIn(where, findOptions);
where = buildNin(where, findOptions);

return where;
}
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export default class StorageService extends TdriveService<StorageAPI> implements
});
} else {
logger.info("Using 'local' connector for storage.");
const defaultHomeDir = this.configuration.get<string>("local.path");
if (defaultHomeDir) this.homeDir = `${defaultHomeDir}`;
// const defaultHomeDir = this.configuration.get<string>("local.path");
// if (defaultHomeDir) this.homeDir = `${defaultHomeDir}`;
logger.trace(`Home directory for the storage: ${this.homeDir}`);
}
logger.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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"});
Expand Down
Loading