Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "Store and reconstruct Marshal dumps chunk at a time"

This reverts commit 4cea33e.

We can't concat Marshal payloads together this easily unless we
completely take them apart because they contain relative indexes for
things like memoized strings, etc.
  • Loading branch information...
commit 2a63730cd87a4105d11c02e75d8fa39dee3615f9 1 parent 4cea33e
@evanphx evanphx authored
Showing with 12 additions and 31 deletions.
  1. +12 −31 app/middleware/api_v1_depedencies.rb
View
43 app/middleware/api_v1_depedencies.rb
@@ -8,7 +8,7 @@ class V1MarshaledDepedencies
TooMany = [413, {},
["Too many gems to resolve, please request less than #{LIMIT}"]]
- def data_for(name)
+ def data_for(name, ary, cache)
gem = Rubygem.find_by_name(name)
raise "Unknown gem - #{name}" unless gem
@@ -23,21 +23,15 @@ def data_for(name)
:platform => ver.platform,
:dependencies => deps.map { |d| [d.name, d.requirements] }
}
-
these << data
+ ary << data
end
- # Strip off the version header
- str = Marshal.dump(these)
- val = str[3].ord
-
- if val == 0 or val > 4
- m = str[4..-1]
- else
- m = str[4+val..-1]
+ if cache
+ cache.set "gem.#{name}", [Marshal.dump(these)].pack("m")
end
- [these.size, m]
+ ary
end
CACHE = Memcached.new("localhost:11211")
@@ -55,43 +49,30 @@ def call(env)
return TooMany if gems.size > LIMIT
- total = 0
- body = []
+ ary = []
cache = CACHE.clone
gems.each do |g|
- key = "gem.#{g}"
-
begin
- n, m = cache.get(key).split(":",2)
-
- total += n.to_i
- body << m
+ data = cache.get "gem.#{g}"
+ ary += Marshal.load(data.unpack("m").first)
rescue Memcached::NotFound
begin
- n, m = data_for(g)
-
- cache.set key, "#{n}:#{m}"
-
- total += n
- body << m
+ data_for g, ary, cache
rescue
return BadRequest
end
rescue Memcached::ServerIsMarkedDead
begin
- n, m = data_for(g)
-
- total += n
- body << m
+ data_for g, ary, nil
rescue
return BadRequest
end
end
end
- body.unshift "\x04\x08[\x04#{[total].pack('V')}"
+ body = Marshal.dump ary
- [200, {}, body]
+ [200, {}, [body]]
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.