UBERF-9114: Optimize memory usage (#7643)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev
2025-01-12 22:54:54 +07:00
committed by GitHub
parent 5263a41cb9
commit 7702c5ef83
7 changed files with 713 additions and 127 deletions
+19 -1
View File
@@ -743,6 +743,8 @@ abstract class PostgresAdapterBase implements DbAdapter {
if (column === 'createdOn' || column === 'modifiedOn') {
const val = Number.parseInt(row[column])
;(doc as any)[column] = Number.isNaN(val) ? null : val
} else if (column === '%hash%') {
// Ignore
} else {
;(doc as any)[column] = row[column] === 'NULL' ? null : row[column]
}
@@ -1285,6 +1287,22 @@ abstract class PostgresAdapterBase implements DbAdapter {
return []
}
stripHash<T extends Doc>(docs: T | T[]): T | T[] {
if (Array.isArray(docs)) {
docs.forEach((it) => {
if ('%hash%' in it) {
delete it['%hash%']
}
return it
})
} else if (typeof docs === 'object' && docs != null) {
if ('%hash%' in docs) {
delete docs['%hash%']
}
}
return docs
}
strimSize (str?: string): string {
if (str == null) {
return ''
@@ -1841,7 +1859,7 @@ class PostgresTxAdapter extends PostgresAdapterBase implements TxAdapter {
const userTx: Tx[] = []
model.forEach((tx) => (tx.modifiedBy === core.account.System && !isPersonAccount(tx) ? systemTx : userTx).push(tx))
return systemTx.concat(userTx)
return this.stripHash(systemTx.concat(userTx)) as Tx[]
}
}
/**
+1 -1
View File
@@ -475,7 +475,7 @@ export function parseDocWithProjection<T extends Doc> (
domain: string,
projection?: Projection<T> | undefined
): T {
const { workspaceId, data, ...rest } = doc
const { workspaceId, data, '%hash%': hash, ...rest } = doc
const schema = getSchema(domain)
for (const key in rest) {
if ((rest as any)[key] === 'NULL' || (rest as any)[key] === null) {