Skip to content

Commit cccfe10

Browse files
ericparshallestolfo
authored andcommitted
Update fs_bucket.rb
Previously, this code was querying all IDs in the collection and storing them in an array. This is very inefficient and causes a long delay when inserting a file into fs.files, especially when the system is under a heavy load.
1 parent 715a582 commit cccfe10

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/mongo/grid/fs_bucket.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def files_name
438438
end
439439

440440
def ensure_indexes!
441-
if files_collection.find({}, projection: { _id: 1 }).to_a.empty?
441+
if files_collection.find({}).count == 0
442442
chunks_collection.indexes.create_one(FSBucket::CHUNKS_INDEX, :unique => true)
443443
files_collection.indexes.create_one(FSBucket::FILES_INDEX)
444444
end

0 commit comments

Comments
 (0)