-
Notifications
You must be signed in to change notification settings - Fork 1k
[backend] Various performance improvments #10971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e74c247
45e68da
72f70b0
fc36372
91e83ff
f5848db
520f0e5
4c7fa6c
7a65016
0324695
906ee51
8211c8a
8cd1dae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1624,7 +1624,7 @@ export const computeQueryIndices = (indices, typeOrTypes, withInferences = true) | |
export const elFindByIds = async (context, user, ids, opts = {}) => { | ||
const { indices, baseData = false, baseFields = BASE_FIELDS } = opts; | ||
const { withoutRels = false, toMap = false, mapWithAllIds = false, type = null } = opts; | ||
const { orderBy = 'created_at', orderMode = 'asc' } = opts; | ||
const { orderBy = null, orderMode = 'asc' } = opts; | ||
const idsArray = Array.isArray(ids) ? ids : [ids]; | ||
const types = (Array.isArray(type) || isEmptyField(type)) ? type : [type]; | ||
const processIds = R.filter((id) => isNotEmptyField(id), idsArray); | ||
|
@@ -1653,6 +1653,7 @@ export const elFindByIds = async (context, user, ids, opts = {}) => { | |
}; | ||
mustTerms.push(should); | ||
if (types && types.length > 0) { | ||
// No cache management is possible, just put the type in the filtering | ||
const shouldType = { | ||
bool: { | ||
should: [ | ||
|
@@ -1671,14 +1672,22 @@ export const elFindByIds = async (context, user, ids, opts = {}) => { | |
// Handle draft | ||
const draftMust = buildDraftFilter(context, user, opts); | ||
const body = { | ||
sort: [{ [orderBy]: orderMode }], | ||
query: { | ||
bool: { | ||
must: [...mustTerms, ...draftMust], | ||
must_not: markingRestrictions.must_not, | ||
}, | ||
// Put everything under filter to prevent score computation | ||
// Search without score when no sort is applied is faster | ||
filter: [{ | ||
bool: { | ||
must: [...mustTerms, ...draftMust], | ||
must_not: markingRestrictions.must_not, | ||
}, | ||
}] | ||
} | ||
}, | ||
}; | ||
if (isNotEmptyField(orderBy)) { | ||
body.sort = [{ [orderBy]: orderMode }]; | ||
} | ||
let searchAfter; | ||
let hasNextPage = true; | ||
while (hasNextPage) { | ||
|
@@ -1688,10 +1697,11 @@ export const elFindByIds = async (context, user, ids, opts = {}) => { | |
const query = { | ||
index: computedIndices, | ||
size: ES_MAX_PAGINATION, | ||
track_total_hits: false, | ||
_source: baseData ? baseFields : true, | ||
body, | ||
}; | ||
logApp.debug('[SEARCH] elInternalLoadById', { query }); | ||
logApp.debug('[SEARCH] elFindByIds', { query }); | ||
const searchType = `${ids} (${types ? types.join(', ') : 'Any'})`; | ||
const data = await elRawSearch(context, user, searchType, query).catch((err) => { | ||
throw DatabaseError('Find direct ids fail', { cause: err, query }); | ||
|
@@ -3033,13 +3043,13 @@ const elQueryBodyBuilder = async (context, user, options) => { | |
let scoreSearchOrder = orderMode; | ||
if (search !== null && search.length > 0) { | ||
const shouldSearch = elGenerateFullTextSearchShould(search, options); | ||
const bool = { | ||
const searchBool = { | ||
bool: { | ||
should: shouldSearch, | ||
minimum_should_match: 1, | ||
}, | ||
}; | ||
mustFilters.push(bool); | ||
mustFilters.push(searchBool); | ||
// When using a search, force a score ordering if nothing specified | ||
if (orderCriterion.length === 0) { | ||
orderCriterion.unshift('_score'); | ||
|
@@ -3059,9 +3069,7 @@ const elQueryBodyBuilder = async (context, user, options) => { | |
} | ||
} | ||
// Add standard_id if not specify to ensure ordering uniqueness | ||
if (!orderCriterion.includes('standard_id')) { | ||
ordering.push({ 'standard_id.keyword': 'asc' }); | ||
} | ||
ordering.push({ _doc: 'asc' }); | ||
// Build runtime mappings | ||
const runtime = RUNTIME_ATTRIBUTES[orderBy]; | ||
if (isNotEmptyField(runtime)) { | ||
|
@@ -3072,8 +3080,8 @@ const elQueryBodyBuilder = async (context, user, options) => { | |
script: { source, params }, | ||
}; | ||
} | ||
} else { // If not ordering criteria, order by standard_id | ||
ordering.push({ 'standard_id.keyword': 'asc' }); | ||
} else { // If not ordering criteria, order by _doc | ||
ordering.push({ _doc: 'asc' }); | ||
Comment on lines
+3083
to
+3084
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure to understand this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it could be simplified by adding |
||
} | ||
// Handle draft | ||
const draftMust = buildDraftFilter(context, user, options); | ||
|
@@ -3405,7 +3413,7 @@ export const elAggregationsList = async (context, user, indexName, aggregations, | |
} | ||
const query = { | ||
index: getIndicesToQuery(context, user, indexName), | ||
track_total_hits: true, | ||
track_total_hits: false, | ||
_source: false, | ||
body, | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this comment is not relevant anymore?