You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The FirestoreReactiveRepository interface doesn't properly implement the findFirst method like Derived Query Methods. Firestore supports limiting the queried results, so a limit is expected in the translated query sent to Firestore using findFirst or findTop syntax.
The implementation of MyEntityRepository is provided by SimpleFirestoreReactiveRepository.java and executed by FirestoreTemplate.java. The following is the built query sent to the method com.google.cloud.spring.data.firestore.FirestoreTemplate:execute when calling findFirstByGroupAndNameOrderByTimeDesc("group1","name1")
where {
composite_filter {
op: AND
filters {
field_filter {
field {
field_path: "group"
}
op: EQUAL
value {
string_value: "group1"
}
}
}
filters {
field_filter {
field {
field_path: "name"
}
op: EQUAL
value {
string_value: "name1"
}
}
}
}
}
order_by {
field {
field_path: "time"
}
direction: DESCENDING
}
Notice, there is no limit in the query. A workaround for this is explicitly pass a Pageable object to the query as follow;
This time, calling findByGroupAndNameOrderByTimeDesc("group1","name1", PageRequest.of(0, 1)) results in the following query which includes a limit:
where {
composite_filter {
op: AND
filters {
field_filter {
field {
field_path: "group"
}
op: EQUAL
value {
string_value: "group1"
}
}
}
filters {
field_filter {
field {
field_path: "name"
}
op: EQUAL
value {
string_value: "name1"
}
}
}
}
}
order_by {
field {
field_path: "time"
}
direction: DESCENDING
}
limit {
value: 1
}
Although there is a workaround for this issue, the significant problem lies in the fact that the SimpleFirestoreReactiveRepository does not throw any unsupported exception; instead, it executes the query while completely ignoring the limit part. This oversight could result in a large number of reads in Firestore and consequently lead to a substantial bill.
Describe the bug
The FirestoreReactiveRepository interface doesn't properly implement the
findFirst
method like Derived Query Methods. Firestore supports limiting the queried results, so a limit is expected in the translated query sent to Firestore usingfindFirst
orfindTop
syntax.Here is a simplified example.
The implementation of
MyEntityRepository
is provided bySimpleFirestoreReactiveRepository.java
and executed byFirestoreTemplate.java
. The following is the built query sent to the methodcom.google.cloud.spring.data.firestore.FirestoreTemplate:execute
when callingfindFirstByGroupAndNameOrderByTimeDesc("group1","name1")
Notice, there is no limit in the query. A workaround for this is explicitly pass a Pageable object to the query as follow;
This time, calling
findByGroupAndNameOrderByTimeDesc("group1","name1", PageRequest.of(0, 1))
results in the following query which includes a limit:Although there is a workaround for this issue, the significant problem lies in the fact that the
SimpleFirestoreReactiveRepository
does not throw any unsupported exception; instead, it executes the query while completely ignoring the limit part. This oversight could result in alarge number of reads
in Firestore and consequently lead to asubstantial bill
.Here is an excerpt of the pom file.
The text was updated successfully, but these errors were encountered: