ENT-6876: Optimised vault query to not query for total state count if the first page isn't full (#7449)

This commit is contained in:
Shams Asari 2023-08-21 10:30:42 +01:00 committed by GitHub
parent 6a22494431
commit 5cdbec9ddf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -706,9 +706,6 @@ class NodeVaultService(
paging: PageSpecification, paging: PageSpecification,
sorting: Sort, sorting: Sort,
contractStateType: Class<out T>): Vault.Page<T> { contractStateType: Class<out T>): Vault.Page<T> {
// calculate total results where a page specification has been defined
val totalStatesAvailable = if (paging.isDefault) -1 else queryTotalStateCount(criteria, contractStateType)
val (query, stateTypes) = createQuery(criteria, contractStateType, sorting) val (query, stateTypes) = createQuery(criteria, contractStateType, sorting)
query.setResultWindow(paging) query.setResultWindow(paging)
@ -732,6 +729,13 @@ class NodeVaultService(
ArrayList() ArrayList()
) )
val totalStatesAvailable = when {
paging.isDefault -> -1L
// If the first page isn't full then we know that's all the states that are available
paging.pageNumber == DEFAULT_PAGE_NUM && states.size < paging.pageSize -> states.size.toLong()
else -> queryTotalStateCount(criteria, contractStateType)
}
return Vault.Page(states, statesMetadata, totalStatesAvailable, stateTypes, otherResults) return Vault.Page(states, statesMetadata, totalStatesAvailable, stateTypes, otherResults)
} }