mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-18 16:31:57 +03:00
Fix cached error (#7439)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
51a55dd803
commit
331af1cbf6
@ -49,17 +49,20 @@ export class QueryJoiner {
|
|||||||
): Promise<FindResult<T>> {
|
): Promise<FindResult<T>> {
|
||||||
// Will find a query or add + 1 to callbacks
|
// Will find a query or add + 1 to callbacks
|
||||||
const q = this.findQuery(_class, query, options) ?? this.createQuery(_class, query, options)
|
const q = this.findQuery(_class, query, options) ?? this.createQuery(_class, query, options)
|
||||||
|
try {
|
||||||
if (q.result === undefined) {
|
if (q.result === undefined) {
|
||||||
q.result = this._findAll(ctx, _class, query, options)
|
q.result = this._findAll(ctx, _class, query, options)
|
||||||
}
|
}
|
||||||
if (q.result instanceof Promise) {
|
if (q.result instanceof Promise) {
|
||||||
q.result = await q.result
|
q.result = await q.result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return q.result as FindResult<T>
|
||||||
|
} finally {
|
||||||
q.callbacks--
|
q.callbacks--
|
||||||
|
|
||||||
this.removeFromQueue(q)
|
this.removeFromQueue(q)
|
||||||
|
}
|
||||||
return q.result as FindResult<T>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private findQuery<T extends Doc>(
|
private findQuery<T extends Doc>(
|
||||||
|
@ -576,15 +576,8 @@ abstract class PostgresAdapterBase implements DbAdapter {
|
|||||||
}
|
}
|
||||||
sqlChunks.push(`WHERE ${this.buildQuery(_class, domain, query, joins, options)}`)
|
sqlChunks.push(`WHERE ${this.buildQuery(_class, domain, query, joins, options)}`)
|
||||||
|
|
||||||
return (await this.mgr.read(ctx.id, async (connection) => {
|
const totalSqlChunks = [...sqlChunks]
|
||||||
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 totalResult = await connection.unsafe(totalSql)
|
|
||||||
const parsed = Number.parseInt(totalResult[0].count)
|
|
||||||
total = Number.isNaN(parsed) ? 0 : parsed
|
|
||||||
}
|
|
||||||
if (options?.sort !== undefined) {
|
if (options?.sort !== undefined) {
|
||||||
sqlChunks.push(this.buildOrder(_class, domain, options.sort, joins))
|
sqlChunks.push(this.buildOrder(_class, domain, options.sort, joins))
|
||||||
}
|
}
|
||||||
@ -592,6 +585,16 @@ abstract class PostgresAdapterBase implements DbAdapter {
|
|||||||
sqlChunks.push(`LIMIT ${options.limit}`)
|
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, ...totalSqlChunks].join(' ')
|
||||||
|
const totalResult = await connection.unsafe(totalSql)
|
||||||
|
const parsed = Number.parseInt(totalResult[0].count)
|
||||||
|
total = Number.isNaN(parsed) ? 0 : parsed
|
||||||
|
}
|
||||||
|
|
||||||
const finalSql: string = [select, ...sqlChunks].join(' ')
|
const finalSql: string = [select, ...sqlChunks].join(' ')
|
||||||
fquery = finalSql
|
fquery = finalSql
|
||||||
const result = await connection.unsafe(finalSql)
|
const result = await connection.unsafe(finalSql)
|
||||||
|
Loading…
Reference in New Issue
Block a user