From 27b54e58217a06eb85481bd66cf3669bdcd45443 Mon Sep 17 00:00:00 2001 From: Andrey Sobolev Date: Thu, 5 Dec 2024 16:05:14 +0700 Subject: [PATCH] UBERF-8620: Fix OOM in fulltext service (#7263) Signed-off-by: Andrey Sobolev --- models/core/src/migration.ts | 14 -------------- server/mongo/src/storage.ts | 7 +++++++ server/postgres/src/storage.ts | 5 ++--- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/models/core/src/migration.ts b/models/core/src/migration.ts index 3e047389d8..4adc408598 100644 --- a/models/core/src/migration.ts +++ b/models/core/src/migration.ts @@ -423,20 +423,6 @@ export const coreOperation: MigrateOperation = { await client.update(DOMAIN_SPACE, { '%hash%': { $exists: true } }, { $set: { '%hash%': null } }) } }, - { - state: 'remove-github-patches', - func: async (client) => { - await client.update( - DOMAIN_TX, - { - objectClass: 'tracker:class:Issue', - collection: 'pullRequests', - 'tx.attributes.patch': { $exists: true } - }, - { $unset: { 'tx.attributes.patch': 1 } } - ) - } - }, { state: 'remove-collection-txes', func: async (client) => { diff --git a/server/mongo/src/storage.ts b/server/mongo/src/storage.ts index 4a9ec46a11..a0bf51cc6b 100644 --- a/server/mongo/src/storage.ts +++ b/server/mongo/src/storage.ts @@ -237,6 +237,13 @@ abstract class MongoAdapterBase implements DbAdapter { cursor = cursor.sort(sort) } } + if (options?.projection !== undefined) { + const projection: Projection = {} + for (const key in options.projection ?? []) { + projection[key] = options.projection[key] + } + cursor = cursor.project(projection) + } return await cursor.toArray() } diff --git a/server/postgres/src/storage.ts b/server/postgres/src/storage.ts index 87f5d87d5d..3e2caa2bb6 100644 --- a/server/postgres/src/storage.ts +++ b/server/postgres/src/storage.ts @@ -393,7 +393,7 @@ abstract class PostgresAdapterBase implements DbAdapter { async rawFindAll(_domain: Domain, query: DocumentQuery, options?: FindOptions): Promise { const domain = translateDomain(_domain) - const select = `SELECT * FROM ${domain}` + const select = `SELECT ${this.getProjection(domain, options?.projection, [])} FROM ${domain}` const sqlChunks: string[] = [] sqlChunks.push(`WHERE ${this.buildRawQuery(domain, query, options)}`) if (options?.sort !== undefined) { @@ -564,7 +564,7 @@ abstract class PostgresAdapterBase implements DbAdapter { toClass: undefined }) } - const select = `SELECT ${this.getProjection(_class, domain, options?.projection, joins)} FROM ${domain}` + const select = `SELECT ${this.getProjection(domain, options?.projection, joins)} FROM ${domain}` const secJoin = this.addSecurity(query, domain, ctx.contextData) if (secJoin !== undefined) { sqlChunks.push(secJoin) @@ -1232,7 +1232,6 @@ abstract class PostgresAdapterBase implements DbAdapter { } private getProjection( - _class: Ref>, baseDomain: string, projection: Projection | undefined, joins: JoinProps[]