spring-data-mongodb
spring-data-mongodb copied to clipboard
Debug line for count() call in ReactiveMongoTemplate happens twice
I was noticing that the exact same debug statement is duplicated in https://github.com/spring-projects/spring-data-mongodb/blob/main/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java#L1153
and on the underlying method call at https://github.com/spring-projects/spring-data-mongodb/blob/main/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java#L1172
So if we have debug logging turned on, it looked like perhaps the [expensive] count query is being done twice, but really it only happens once. I'd suggest changing or removing the debug statement on line 1153 in favor of 1172.
As it is today, the output (with debug turned on of course) looks like this, though count is only executed once:
2023-03-08T13:07:50.389-07:00 DEBUG 21153 --- [ctor-http-nio-3] o.s.d.m.core.ReactiveMongoTemplate : Executing count: { "tenantId" : "effa4be0-573d-11e9-8647-d663bd873d93", "$or" : [{ "language" : { "$regularExpression" : { "pattern" : "en", "options" : "i"}}}, { "language" : { "$regularExpression" : { "pattern" : "fr", "options" : "i"}}}]} in collection: session
2023-03-08T13:07:50.390-07:00 DEBUG 21153 --- [ctor-http-nio-3] o.s.d.m.core.ReactiveMongoTemplate : Executing count: { "tenantId" : "effa4be0-573d-11e9-8647-d663bd873d93", "$or" : [{ "language" : { "$regularExpression" : { "pattern" : "en", "options" : "i"}}}, { "language" : { "$regularExpression" : { "pattern" : "fr", "options" : "i"}}}]} in collection: session