Permalink
Browse files

Improving performance of asking for collection names

  • Loading branch information...
1 parent e5b290f commit 0f3cc467d6671087f3115901a215e10719bb67b7 @durran durran committed Jun 21, 2012
Showing with 11 additions and 5 deletions.
  1. +5 −5 lib/moped/database.rb
  2. +6 −0 perf/cases.rb
View
@@ -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
View
@@ -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.