Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Improving performance of asking for collection names
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jun 21, 2012
1 parent e5b290f commit 0f3cc46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/moped/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ def collections
#
# @since 1.0.0
def collection_names
Collection.new(self, "system.namespaces").
find(name: { "$not" => /system|\$/ }).
map do |doc|
doc["name"].sub(/^#{name}./, '')
end
namespaces = Collection.new(self, "system.namespaces").find(name: { "$not" => /system|\$/ })
namespaces.map do |doc|
_name = doc["name"]
_name[name.length + 1, _name.length]
end
end
end
end
6 changes: 6 additions & 0 deletions perf/cases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@
end
end.each &:join
end

profile "Ask for all collection names, 1000x" do
1_000.times do
session.collection_names
end
end

0 comments on commit 0f3cc46

Please sign in to comment.