[CDRIVER-2026] mongoc_gridfs_find_one_with_opts() is not internally optimized for fetching one result Created: 04/Feb/17  Updated: 07/May/18  Resolved: 09/May/17

Status: Closed
Project: C Driver
Component/s: GridFS
Affects Version/s: 1.5.3
Fix Version/s: 1.7.0

Type: Improvement Priority: Minor - P4
Reporter: Arseny Vakhrushev Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

As seen here https://github.com/mongodb/mongo-c-driver/blob/7f1dd3630d6bb4b8d5db4c2b865c328acd170012/src/mongoc/mongoc-gridfs.c#L236 ,
there is no code that sets the limit = 1 option for the call to _mongoc_gridfs_file_list_new_with_opts().

As a consequence, the code will always fetch all results (unless explicitly overridden by the user of course) from the server whereas it does in fact use only the first one as a return value. This in turn eliminates any performance gain one could expect from using this function.

One proposed solution would be to always set the limit = 1 option before calling _mongoc_gridfs_file_list_new_with_opts(). For example:

...
bson_t new_opts;
bson_init(&new_opts);
if (opts) bson_copy_to_excluding_noinit(opts, &new_opts, "limit", (char *)NULL);
BSON_APPEND_INT32(&new_opts, "limit", 1);
 
list = _mongoc_gridfs_file_list_new_with_opts (gridfs, filter, new_opts);
...



 Comments   
Comment by Githook User [ 09/May/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-2026 optimize mongoc_gridfs_find_one_with_opts
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/9a8f9b79514787d258ed09fd03a36b1d147f357f

Generated at Wed Feb 07 21:13:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.