spring-projects / spring-data-mongodb

Provides support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-mongodb/
Apache License 2.0
1.62k stars 1.09k forks source link

Debug line for count() call in ReactiveMongoTemplate happens twice #4322

Open rhanton opened 1 year ago

rhanton commented 1 year ago

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
christophstrobl commented 1 year ago

related to #4253

abimael-turing commented 6 months ago

Hi @christophstrobl, may I assist you with this issue?