Skip to content

Commit b802a5c

Browse files
authored
fix(entity): calculate the count of entities when offset is out of range (#851)
1 parent a0a31cd commit b802a5c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

search-service/src/main/kotlin/com/egm/stellio/search/service/QueryService.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ class QueryService(
3838
queryParams,
3939
accessRightFilter
4040
)
41-
if (entitiesIds.isEmpty())
42-
return@either Pair<List<JsonLdEntity>, Int>(emptyList(), 0)
43-
4441
val count = temporalEntityAttributeService.getCountForEntities(
4542
queryParams,
4643
accessRightFilter
4744
).bind()
4845

46+
// we can have an empty list of entities with a non-zero count (e.g., offset too high)
47+
if (entitiesIds.isEmpty())
48+
return@either Pair<List<JsonLdEntity>, Int>(emptyList(), count)
49+
4950
val entitiesPayloads =
5051
entityPayloadService.retrieve(entitiesIds)
5152
.map { toJsonLdEntity(it, listOf(queryParams.context)) }

search-service/src/test/kotlin/com/egm/stellio/search/service/QueryServiceTests.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,13 @@ class QueryServiceTests {
9797
@Test
9898
fun `it should return an empty list if no entity matched the query`() = runTest {
9999
coEvery { temporalEntityAttributeService.getForEntities(any(), any()) } returns emptyList()
100+
coEvery { temporalEntityAttributeService.getCountForEntities(any(), any()) } returns 0.right()
100101

101102
queryService.queryEntities(buildDefaultQueryParams()) { null }
102103
.shouldSucceedWith {
103104
assertEquals(0, it.second)
104105
assertTrue(it.first.isEmpty())
105106
}
106-
107-
coVerify { temporalEntityAttributeService.getCountForEntities(any(), any()) wasNot Called }
108107
}
109108

110109
@Test

0 commit comments

Comments
 (0)