Fix cached error (#7439)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-12-12 14:39:19 +05:00 committed by GitHub
parent 51a55dd803
commit 331af1cbf6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 16 deletions

View File

@ -49,17 +49,20 @@ export class QueryJoiner {
): Promise<FindResult<T>> {
// Will find a query or add + 1 to callbacks
const q = this.findQuery(_class, query, options) ?? this.createQuery(_class, query, options)
if (q.result === undefined) {
q.result = this._findAll(ctx, _class, query, options)
}
if (q.result instanceof Promise) {
q.result = await q.result
}
q.callbacks--
try {
if (q.result === undefined) {
q.result = this._findAll(ctx, _class, query, options)
}
if (q.result instanceof Promise) {
q.result = await q.result
}
this.removeFromQueue(q)
return q.result as FindResult<T>
} finally {
q.callbacks--
return q.result as FindResult<T>
this.removeFromQueue(q)
}
}
private findQuery<T extends Doc>(

View File

@ -576,21 +576,24 @@ abstract class PostgresAdapterBase implements DbAdapter {
}
sqlChunks.push(`WHERE ${this.buildQuery(_class, domain, query, joins, options)}`)
const totalSqlChunks = [...sqlChunks]
if (options?.sort !== undefined) {
sqlChunks.push(this.buildOrder(_class, domain, options.sort, joins))
}
if (options?.limit !== undefined) {
sqlChunks.push(`LIMIT ${options.limit}`)
}
return (await this.mgr.read(ctx.id, async (connection) => {
let total = options?.total === true ? 0 : -1
if (options?.total === true) {
const totalReq = `SELECT COUNT(${domain}._id) as count FROM ${domain}`
const totalSql = [totalReq, ...sqlChunks].join(' ')
const totalSql = [totalReq, ...totalSqlChunks].join(' ')
const totalResult = await connection.unsafe(totalSql)
const parsed = Number.parseInt(totalResult[0].count)
total = Number.isNaN(parsed) ? 0 : parsed
}
if (options?.sort !== undefined) {
sqlChunks.push(this.buildOrder(_class, domain, options.sort, joins))
}
if (options?.limit !== undefined) {
sqlChunks.push(`LIMIT ${options.limit}`)
}
const finalSql: string = [select, ...sqlChunks].join(' ')
fquery = finalSql