UBERF-4319: Fix create issue performance (#4608)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2024-02-13 01:42:16 +07:00 committed by GitHub
parent 3d0056f371
commit 466298d425
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 51 additions and 17 deletions

View File

@ -304,6 +304,29 @@ export class OptimizeQueryMiddleware extends BasePresentationMiddleware implemen
console.error('_class must be specified in query', query)
return toFindResult([], 0)
}
return await this.provideFindAll(_class, query, options)
const fQuery = { ...query }
const fOptions = { ...options }
this.optimizeQuery<T>(fQuery, fOptions)
return await this.provideFindAll(_class, fQuery, fOptions)
}
private optimizeQuery<T extends Doc>(fQuery: DocumentQuery<T>, fOptions: FindOptions<T>): void {
if (typeof fQuery._id === 'string' && fOptions.sort !== undefined) {
delete fOptions.sort
}
if (fOptions.lookup !== undefined && Object.keys(fOptions.lookup).length === 0) {
delete fOptions.lookup
}
}
async findOne<T extends Doc>(
_class: Ref<Class<T>>,
query: DocumentQuery<T>,
options?: FindOptions<T> | undefined
): Promise<WithLookup<T> | undefined> {
const fQuery = { ...query }
const fOptions = { ...options }
this.optimizeQuery<T>(fQuery, fOptions)
return await this.provideFindOne(_class, fQuery, fOptions)
}
}

View File

@ -137,7 +137,6 @@ class UIClient extends TxOperations implements Client, MeasureClient {
this.measureOp = undefined
if (this.afterMeasure.length > 0) {
const txes = this.afterMeasure
console.log('after measture', txes)
this.afterMeasure = []
for (const tx of txes) {
await this.doNotify(tx)

View File

@ -34,6 +34,7 @@ import core, {
SearchQuery,
SearchResult,
SortingQuery,
Space,
Tx,
TxCollectionCUD,
TxCreateDoc,
@ -200,6 +201,11 @@ export class LiveQuery extends TxProcessor implements Client {
modifiedOn: 1
}
}
if (options === undefined) {
options = {}
}
options.limit = 1
const q = this.findQuery(_class, query, options) ?? this.createDumpQuery(_class, query, options)
if (q.result instanceof Promise) {
q.result = await q.result
@ -393,8 +399,8 @@ export class LiveQuery extends TxProcessor implements Client {
return false
}
private async getCurrentDoc (q: Query, _id: Ref<Doc>): Promise<boolean> {
const current = await this.client.findOne(q._class, { _id }, q.options)
private async getCurrentDoc (q: Query, _id: Ref<Doc>, space: Ref<Space>): Promise<boolean> {
const current = await this.client.findOne(q._class, { _id, space }, q.options)
if (q.result instanceof Promise) {
q.result = await q.result
}
@ -480,7 +486,7 @@ export class LiveQuery extends TxProcessor implements Client {
continue
}
} else {
const currentRefresh = await this.getCurrentDoc(q, updatedDoc._id)
const currentRefresh = await this.getCurrentDoc(q, updatedDoc._id, updatedDoc.space)
if (currentRefresh) {
continue
}
@ -568,7 +574,7 @@ export class LiveQuery extends TxProcessor implements Client {
const updateRefresh = await this.checkUpdatedDocMatch(q, updatedDoc)
if (updateRefresh) return
} else {
const currentRefresh = await this.getCurrentDoc(q, updatedDoc._id)
const currentRefresh = await this.getCurrentDoc(q, updatedDoc._id, updatedDoc.space)
if (currentRefresh) return
}
}

View File

@ -54,8 +54,6 @@ export interface QueryWithResult {
findOne: boolean
}
export const transactions: TxWitHResult[] = []
class ModelClient implements AccountClient {
notifyEnabled = true
constructor (readonly client: AccountClient) {
@ -92,6 +90,7 @@ class ModelClient implements AccountClient {
query: DocumentQuery<T>,
options?: FindOptions<T>
): Promise<WithLookup<T> | undefined> {
const startTime = Date.now()
const result = await this.client.findOne(_class, query, options)
if (this.notifyEnabled) {
console.debug(
@ -103,7 +102,8 @@ class ModelClient implements AccountClient {
result,
' =>model',
this.client.getModel(),
getMetadata(devmodel.metadata.DevModel)
getMetadata(devmodel.metadata.DevModel),
Date.now() - startTime
)
}
return result
@ -114,6 +114,7 @@ class ModelClient implements AccountClient {
query: DocumentQuery<T>,
options?: FindOptions<T>
): Promise<FindResult<T>> {
const startTime = Date.now()
const result = await this.client.findAll(_class, query, options)
if (this.notifyEnabled) {
console.debug(
@ -125,7 +126,8 @@ class ModelClient implements AccountClient {
result,
' =>model',
this.client.getModel(),
getMetadata(devmodel.metadata.DevModel)
getMetadata(devmodel.metadata.DevModel),
Date.now() - startTime
)
}
return result
@ -140,13 +142,10 @@ class ModelClient implements AccountClient {
}
async tx (tx: Tx): Promise<TxResult> {
const startTime = Date.now()
const result = await this.client.tx(tx)
if (this.notifyEnabled) {
console.debug('devmodel# tx=>', tx, result, getMetadata(devmodel.metadata.DevModel))
}
transactions.push({ tx, result })
if (transactions.length > 100) {
transactions.shift()
console.debug('devmodel# tx=>', tx, result, getMetadata(devmodel.metadata.DevModel), Date.now() - startTime)
}
return result
}

View File

@ -359,7 +359,11 @@
try {
const operations = client.apply(_id)
const lastOne = await client.findOne<Issue>(tracker.class.Issue, {}, { sort: { rank: SortingOrder.Descending } })
const lastOne = await client.findOne<Issue>(
tracker.class.Issue,
{ space: _space },
{ sort: { rank: SortingOrder.Descending } }
)
const incResult = await client.updateDoc(
tracker.class.Project,
core.space.Space,
@ -449,7 +453,10 @@
draftController.remove()
descriptionBox?.removeDraft(false)
isAssigneeTouched = false
console.log('createIssue measure', doneOp())
const d1 = Date.now()
void doneOp().then((res) => {
console.log('createIssue measure', res, Date.now() - d1)
})
} catch (err: any) {
console.error(err)
await doneOp() // Complete in case of error