Permalink
Browse files

pipeline up the redis calls

  • Loading branch information...
1 parent 0966571 commit d3b915fe98bd0774e76d85679cc6546aa605473e @qrush qrush committed Mar 7, 2012
Showing with 23 additions and 12 deletions.
  1. +23 −12 app/models/dependency.rb
View
@@ -28,19 +28,30 @@ def self.runtime_key(full_name)
# rails,rack,bundler
def self.for(gem_list)
- gem_list.map do |rubygem_name|
- versions = $redis.lrange(Rubygem.versions_key(rubygem_name), 0, -1)
- versions.map do |version|
- info = $redis.hgetall(Version.info_key(version))
- deps = $redis.lrange(Dependency.runtime_key(version), 0, -1)
- {
- :name => info["name"],
- :number => info["number"],
- :platform => info["platform"],
- :dependencies => deps.map { |dep| dep.split(" ", 2) }
- }
+ versions = $redis.pipelined do
+ gem_list.each do |rubygem_name|
+ $redis.lrange(Rubygem.versions_key(rubygem_name), 0, -1)
end
- end.flatten
+ end || []
+ versions.flatten!
+
+ return [] if versions.blank?
+
+ data = $redis.pipelined do
+ versions.each do |version|
+ $redis.hvals(Version.info_key(version))
+ $redis.lrange(Dependency.runtime_key(version), 0, -1)
+ end
+ end
+
+ data.in_groups_of(2).map do |(name, number, platform), deps|
+ {
+ :name => name,
+ :number => number,
+ :platform => platform,
+ :dependencies => deps.map { |dep| dep.split(" ", 2) }
+ }
+ end
end
def name

0 comments on commit d3b915f

Please sign in to comment.