Skip to content

GridFsTemplate.getGridFs() shouldn't create a new GridFS instance for every invocation [DATAMONGO-1441] #2352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue May 30, 2016 · 4 comments
Assignees
Labels
in: core Issues in core support type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

Derek opened DATAMONGO-1441 and commented

Why create GridFS(new GridFS) everytime?
In GridFS constructor, " filesCollection.count() ,chunksCollection.count()" excute everytime


Affects: 1.8.4 (Gosling SR4), 1.9.1 (Hopper SR1), 1.8.6 (Gosling SR6), 1.9.5 (Hopper SR5), 1.10 GA (Ingalls)

Reference URL: https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/gridfs/GridFsTemplate.java

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

Depending on how MongoDBFactory is implemented, each call to it could potentially return a different DB instance every time, so the big question basically becomes on what scope to cache the GridFS instance. To be completely honest, I wasn't expecting the constructor to issue database calls in the first place.

We could of course go ahead and keep GridFS instances around per Db but I am kind of wondering wha implications this has for the resources we keep alive by that (the DBCollection instances within GridFS instances etc.).

@spring-projects-issues
Copy link
Author

Derek commented

Thank you very much for your reply!

Now I know that why 'new GridFS' every time. But because of this, we will call :
{ "count" : "fs.files", "query" : { } }}
{ "count" : "fs.chunks", "query" : { } }}
before each 'find(), store(), delete()', I just expecting to reduce the two query. ^_^

@spring-projects-issues
Copy link
Author

Derek commented

This caused count all 'files' and 'chunks' collections before invoke 'find(), store(), delete()' every time! It is so bad!!
I am looking forward to fix it! Thank you!

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core support labels Dec 30, 2020
@christophstrobl
Copy link
Member

Resolved via #1627.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants